Asp. NET to prevent refreshing the automatic trigger event solution _ Practical Tips

Source: Internet
Author: User
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!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.