When updatepanel is used for partial refresh, sometimes it takes a long wait time. At this time, if there is a "cancel" button, it can provide a lot of convenience for human-computer interaction.
In the followingCode.
< Script Language = "JavaScript" Type = "Text/JavaScript" >
<! --
VaR PRM = SYS. webforms. pagerequestmanager. getinstance ();
Function Cancelasyncpostback (){
If (PRM. get_isinasyncpostback ()){
PRM. abortpostback ();
}
}
// -->
</ Script >
Next, use an HTML control to call this js method to complete the "cancel" effect. All the code is as follows:
Code
<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Abortpostback. aspx. CS " Inherits = " Abortpostback " %>
<!Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head Runat = "Server" >
< Title > Untitled page </ Title >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Div >
< ASP: scriptmanager ID = "Scriptmanager1" Runat = "Server" >
</ ASP: scriptmanager >
< Script Language = "JavaScript" Type = "Text/JavaScript" >
VaR PRM = SYS. webforms. pagerequestmanager. getinstance ();
Function Cancelasyncpostback (){
If (PRM. get_isinasyncpostback ()){
PRM. abortpostback ();
}
}
</ Script >
< ASP: updatepanel ID = "Updatepanel1" Runat = "Server" >
< Contenttemplate >
< ASP: button ID = "Button1" Runat = "Server" Text = "Update" Onclick = "Button#click" />
< ASP: textbox ID = "Textbox1" Runat = "Server" > </ ASP: textbox >
</ Contenttemplate >
</ ASP: updatepanel >
< ASP: updateprogress ID = "Updateprogress1" Runat = "Server"
Associatedupdatepanelid = "Updatepanel1" >
< Progresstemplate >
Updating. < Input ID = "Button2" Type = "Button" Value = "Cancel" Onclick = "Cancelasyncpostback ();" />
</ Progresstemplate >
</ ASP: updateprogress >
</ Div >
</ Form >
</ Body >
</ Html >
References:
Msdn: http://msdn.microsoft.com/en-us/library/bb386518.aspx