Search code examples
asp.netsqlasp.net-membershiplinkbutton

How to limit clicks on LinkButton


I have some textboxes with linkbuttons. The linkbutton does some updates to some SQL tables.

I also have members club (aspnet membership), and apparently every user has a userid (GUID).

I want to limit the number of clicks to 3 clicks per day on that LinkButton. If they click more than 3 per day, the linkbutton will be disabled.

How can i do that? I don't know from where to start.


Solution

  • You'll need to store some sort of counter associated to the user. Cache would probably be the most appropriate place as you can specify an expiration, which you'll need to reset the click count each day.

    Something like this should work:

    Cache.Insert(base.User.UserID.ToString(), 0, null, DateTime.Today.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration); 
    

    The above will store the userID in cache until midnight of the next day, and then it will be reset. Each time the user clicks the button, increment the value stored in cache, and once the number of clicks reaches three (3), disable the button.