定义一个更新显示进度控件,其中添加取消按钮
<script language="c#">
// Click事件提供取消的延时
public void btn_clicked(object sender, EventArges e)
{
System.Threading.Thread.Sleep(1000);
}
</script>
<asp:ScriptManager id="ScriptManager" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel id="up1" runat="server">
<ContentTemplate>
<% =System.Now.ToString() %>
<asp:Button id="btn_UpdateTime" runat="server" value="Update" onClick="btn_clicked">
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="inprocess" runat="server">
<ProgressTemplate>
<input type="button" value="取消更新" onclick="cancel_update()" />
</ProgressTemplate>
</asp:UpdateProgress>
<script language="javascript" >
// 获取页面请求对象
// 判断是否还在进行异步存取,如果仍在存取中,则进行取消
var prm = Sys.WebForms.PageRequestManager.getInstance();
function cancel_update()
{
if (prm.get_isInAsyncPostBack ())
{
prm.abortPostBack();
}
}
</script>