With ASP.net, server-side events are automatically triggered when the page is refreshed. To give a simple example, such as: a registration page, we fill out the registration information, if you press F5 Refresh, will automatically trigger to the button event, which caused another registration of trouble.
My previous solution: Use keyword queries, and if they are the same, prompt already.
But such a scheme cannot be used without a table, and he will resubmit it. In view of this, I am looking for a new solution, I am glad, in a friend's point, burst out such a solution, there must be a better solution, generous enlighten.
Solution: When refreshing, catch keypress and let him trigger other useless events.
1, capturing the F5 event JavaScript
Window.document.onkeydown = keystroke;
function keystroke ()
{
var key = Event.keycode;
Event.srcElement.releaseCapture ();
if (key = = 116)
{
document.getElementById ("Button1"). Click ();
event.keycode=0;
Event.returnvalue=false;
}
}
2, aspx page to place a button
<asp:button id= "Button1" style= "z-index:102; left:344px; Position:absolute; top:408px; width:0px; "runat=" Server "
text= "button" ></asp:Button>
3. Button Event
private void Button1_Click (object sender, System.EventArgs e)
{
Response.Write ("You have pressed the key F5");
}
This "Shere" solution, can solve the problem of refreshing the automatic trigger event, if anyone has a better plan, wish to tell me, thank you!