On the Internet, we often interact with users through table lists.
However, because the Web response is slow and fast, the table information may be sent out, resulting in a duplicate loading of the data.
Asp.net has a small way to defend against such situations.
Protected void page_load (Object sender, eventargs E)
...{
If (! Page. ispostback)
...{
Button1.attributes ["onclick"] = "This. Disabled = true;" +
Page. clientscript. getpostbackeventreference (button1 ,"");
}
}
Protected void button#click (Object sender, eventargs E)
...{
System. Threading. thread. Sleep (5000 );
}
When page load is performed, add an onclick attribute to the button. After you press the button, disable yourself and then issue the form submit statement.
<Div>
<Input type = "hidden" name = "_ eventtarget" id = "_ eventtarget" value = ""/>
<Input type = "hidden" name = "_ eventargument" id = "_ eventargument" value = ""/>
<Input type = "hidden" name = "_ viewstate" id = "_ viewstate" value = "/comment + j8gjxshabhpv4 ="/>
</Div>
<SCRIPT type = "text/JavaScript">
<! --
VaR theform = Document. Forms ['form1'];
If (! Theform ){
Theform = Document. form1;
}
Function _ dopostback (eventtarget, eventargument ){
If (! Theform. onsubmit | (theform. onsubmit ()! = False )){
Theform. _ eventtarget. value = eventtarget;
Theform. _ eventargument. value = eventargument;
Theform. Submit ();
}
}
// -->
</SCRIPT>
<Div>
<Input type = "Submit" name = "button1" value = "button" onclick = "this. disabled = true ;__ dopostback ('button1', '');" id = "button1"/>
</Div>
<Div>
In this way, the user can avoid re-clicking the button.