Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent page refresh on pressing F5

I have Created form with Server Side control like button..and also have written event on that.. Now runtime after click on the button i have refreshed the page by pressing F5.Page_load is executing fine but button1_click() event also firing...So how can i stop this event execution in this scenario.Please suggest me

like image 723
karthik k Avatar asked Nov 28 '22 23:11

karthik k


2 Answers

Short Answer: Not possible

Longer Answer: No web site can block the browser's functionality as that would be a serious security concern for the browser.

like image 152
Joel Martinez Avatar answered Nov 30 '22 11:11

Joel Martinez


Welcome to web development, there is no way to stop the page from refreshing and reposting, this is entirely a browser behavior.

There are work arounds though; one simple thing that you can do is after processing your button click, you can redirect the browser back to the page so that a refresh will not include a repost of your button press. Obviously this might require some other state management system (rather than view-state), maybe you can store your state in the Session.

like image 31
CodingGorilla Avatar answered Nov 30 '22 13:11

CodingGorilla