<% @ Page Language = "C #" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<SCRIPT runat = "server">
Protected void button_click (Object sender, eventargs E)
{
System. Threading. thread. Sleep (3000 );
}
</SCRIPT>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "head1" runat = "server">
<Title> updateprogress example </title>
<Style type = "text/CSS">
# Updatepanel1, # updatepanel2, # updateprogress1 {
Border-Right: Gray 1px solid; border-top: Gray 1px solid;
Border-left: Gray 1px solid; border-bottom: Gray 1px solid;
}
# Updatepanel1, # updatepanel2 {
Width: 200px; Height: 200px; position: relative;
Float: Left; margin-left: 10px; margin-top: 10px;
}
# Updateprogress1 {
Width: 400px; Background-color: # ffc080;
Bottom: 0%; left: 0px; position: absolute;
}
</Style>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: scriptmanager id = "scriptmanager1" runat = "server"/>
<SCRIPT type = "text/JavaScript">
VaR PRM = SYS. webforms. pagerequestmanager. getinstance ();
PRM. add_initializerequest (initializerequest );
PRM. add_endrequest (endrequest );
VaR postbackelement;
Function initializerequest (sender, argS ){
If (PRM. get_isinasyncpostback ())
{
Args. set_cancel (true );
}
Postbackelement = args. get_postbackelement ();
If (postbackelement. ID = 'buttontrigger ')
{
$ Get ('updateprogress1'). style. Display = "Block ";
}
}
Function endrequest (sender, argS ){
If (postbackelement. ID = 'buttontrigger ')
{
$ Get ('updateprogress1'). style. Display = "NONE ";
}
}
Function abortpostback (){
If (PRM. get_isinasyncpostback ()){
PRM. abortpostback ();
}
}
</SCRIPT>
<Asp: button id = "buttontrigger" runat = "server" text = "Refresh Panel 1" onclick = "button_click"/>
<Asp: updatepanel id = "updatepanel1" updatemode = "Conditional" runat = "server">
<Contenttemplate>
<% = Datetime. Now. tostring () %> <br/>
The trigger for this Panel
Causes the updateprogress to be displayed
Even though the updateprogress is associated
With panel 2.
<Br/>
</Contenttemplate>
<Triggers>
<Asp: asyncpostbacktrigger controlid = "buttontrigger"/>
</Triggers>
</ASP: updatepanel>
<Asp: updatepanel id = "updatepanel2" updatemode = "Conditional" runat = "server">
<Contenttemplate>
<% = Datetime. Now. tostring () %> <br/>
<Asp: button id = "button2" runat = "server" text = "Refresh panel" onclick = "button_click"/>
</Contenttemplate>
</ASP: updatepanel>
<Asp: updateprogress id = "updateprogress1" runat = "server" associatedupdatepanelid = "updatepanel2">
<Progresstemplate>
Update in progress...
<Input type = "button" value = "stop" onclick = "abortpostback ()"/>
</Progresstemplate>
</ASP: updateprogress>
</Div>
</Form>
</Body>
</Html>