I checked a lot of methods on the Internet, but it is not easy to do so. I 'd like to write one by myself. The idea is to use Javascript to change the next onclick event of the button to return false on the client when the button is pressed; in this way, the server page will not Post to the server if you click the button again before sending it back to the client. At the same time, change the style of the button to a line of text, and the cursor will also become an hourglass. After the server page is re-generated, the Button returns to the initial state. This method does not prevent F5 refreshing, but simply closes the F5 button. To prevent another submission during refreshing, you can clear some TextBox controls before returning the page, in this way, you can judge that if the TextBox is empty, no subsequent operations (such as writing a database) will be performed ). Or jump to another page after the background operation is successful to prevent malicious refresh. It is mainly used in the enterprise intranet, not to prevent hackers, so it is not very strict.
The reference content is as follows: br/> <Head runat = "server">
<Title> multiple web page tests are prohibited. </title>
<Style type = "text/css">
. Disable
{
Border-style: none;
Border-width: thin;
Background-color: Transparent;
Color: # CCCCCC;
Cursor: wait;
}
</Style>
<Script type = "text/javascript" language = "javascript">
Function DisableButton ()
{
Document. getElementById ("Button2"). className = "disable ";
Document. getElementById ("Button2"). value = 'submitting .';
Document. getElementById ("Button2"). onclick = Function ("return false ;");
Return true;
}
Document. onkeydown = mykeydown;
Function mykeydown ()
{
If (event. keyCode = 116) // block the F5 refresh key
{
Window. event. keyCode = 0;
Return false;
}
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
Enter some content <asp: TextBox ID = "TextBox1" runat = "server"> </asp: TextBox>
<Br/>
<Asp: ListBox ID = "ListBox1" runat = "server" Height = "77px" Width = "332px">
</Asp: ListBox> <br/>
<Asp: Button ID = "Button2" runat = "server" Text = "OK" Width = "77px"
Onclick = "Button2_Click"/>
</Div>
</Form>
</Body>
</Html> |