Reputation: 4868
I need to detect when a user refreshing the page in the Page_Init event to stop them from executing the same code twice. What's the way to do this in ASP.NET
thanks
Upvotes: 1
Views: 1162
Reputation: 7930
You can set cookie with short expiration time after first request on your site. Then you can simply check it and enlarge the cookie expiration.
Upvotes: 0
Reputation: 10219
Here's an article that talks about some different ways of dealing with this problem, though I'm not sure it matches 100% with your situation.
Upvotes: 2
Reputation: 351698
Yes, the Page.IsPostBack
property:
Gets a value indicating whether the page is being loaded in response to a client postback, or if it is being loaded and accessed for the first time.
Upvotes: 1