Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
871 views
in Technique[技术] by (71.8m points)

asp.net - Button click event called again when page is refreshed using F5

I found that if you press F5 or refresh from browser window, the last event fires again. For ex. I have clicked on a button the button event is carried out normally, but if i press F5 from browser window then the same event is fired again.

Could someone have any idea?

Thanks for sharing your valuable time.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As per NinenthSense, thats how the browser reacts when the user refresh the page.

If you still want to restrict you can go for some javascript like below

//to avaoid pressing F5 key

document.onkeydown = function()
 {
          if(event.keyCode==116) {
          event.keyCode=0;
          event.returnValue = false;
          }
}

//to avoid refresh, using context menu of the browser

document.oncontextmenu = function() {event.returnValue = false;}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...