二、使用UpdateProgress控件
1. UpdateProgress重要属性/方法
|
属性/方法
|
说明
|
|
DisplayAfter
|
该属性设置多少时间后才出现提示信息,单位为毫秒,默认为500毫秒。
|
|
DynamicLayout
|
设定UpdateProgress是否占位,默认值为True。
|
|
Visible
|
UpdateProgress信息是否可见,默认值为True。
|
|
associatedUpdatePanelID
|
指定UpdateProgress绑定的UpdatePanel的ID。
|
2. 使用UpdateProgress控件
使用下面这个示例来简单的学习UpdateProgress的使用。我们使用上面讲到的Timer来触发一个异步更新,在触发事件Tick中让线程停止3秒,这样我们就可以看到UpdateProgress中的提示信息”Process…”了。下面是源代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UpdateProgress.aspx.cs" Inherits="UpdateProgress" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UpdateProgress.aspx.cs" Inherits="UpdateProgress" %>
<!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>无标题页</title>
<script runat="server">
void Timer1_Tick(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="2000" OnTick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
Process...
</ProgressTemplate>
</asp:UpdateProgress>
</form>
</body>
</html>
<head runat="server">
<title>无标题页</title>
<script runat="server">
void Timer1_Tick(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="2000" OnTick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
Process...
</ProgressTemplate>
</asp:UpdateProgress>
</form>
</body>
</html>
假如上面的程序中,UpdateProgress的属性AssociateUpdatePanelID没有指定为UpdatePanel1是不会出现“Process…”的,我们可以通过这个属性来处理多个UpdatePanel的等待信息。如果DisplayAfter的值设置为大于3秒也是不会出现“Process…”的。
3. UpdateProgress控件使用总结
UpdateProgress的存在让我们的异步更新程序的界面更加友好。我们可以通过各种方式提示用户系统正在处理信息,与此同时,用户可以进行其它的操作,而不用在那边无聊的等待。