When you use asp.net to refresh the page, events on the server are automatically triggered. For example, after entering the registration information on a registration page, if you press F5 to refresh it, it will be automatically triggered to the Button event, in this way, the trouble of registering again is caused.
My previous solution: Query with keywords. If they are the same, the system prompts that the user already exists.
However, this solution cannot be used without table recognition. It will be submitted again. In view of this, I have searched for a new solution. Fortunately, with my friend's suggestion, I have provided such a solution. I am sure I have a better solution.
Solution: capture KeyPress during refresh to trigger other useless events.
1. JavaScript for capturing F5 events
Required parameter Doc ument. 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. Place a Button on the aspx page.
<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 button#click (object sender, System. EventArgs e)
{
Response. Write ("You have pressed the key F5 ");
}
This "Car Care coach" solution can solve the small problem of refreshing the automatically triggered event solution. If anyone has a better solution, I 'd like to say it to you. I am very grateful!