UpdaeProgress的簡單用法

這個控件相比其他控件,屬性少 使用簡單,就先把這個控件的一般使用方法簡單紀錄下

UpdateProgress  應該就是“更新進度” 的意思吧。

屬性:AssociatedUpdatePanelID 輔助的UpdatePanel的id
         DynamicLayout    默認爲true  不佔用頁面控件,提示時候擠開一行空白
                                   設置爲 false  頁面給顯示的內容留行空白


使用方法:

     1.添加一個ScriptManager控件

     2.添加一個UpdatePanel控件

     3.添加一個UpdateProgress控件 

      設置UpdateProgress控件的AssociatedUpdatePanelID爲第2步 UpdatePanel的ID(如果頁面中有多個UpdatePanel則,只有相應updatePanel關聯的updateProgress顯示)
   
 測試例子代碼:
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2. <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head id="Head1" runat="server">
  6. <title>Untitled Page</title>
  7. <style type="text/css">
  8.     #UpdatePanel1, #UpdatePanel2, #UpdateProgress1 { 
  9.       border-right: gray 1px solid; border-top: gray 1px solid; 
  10.       border-left: gray 1px solid; border-bottom: gray 1px solid;
  11.     }
  12.     #UpdatePanel1, #UpdatePanel2 { 
  13.       width:200px; height:200px; position: relative;
  14.       float: left; margin-left: 10px; margin-top: 10px;
  15.      }
  16.      #UpdateProgress3 {
  17.       width: 200px; background-color: #FFC080; 
  18.       bottom: 0%; left: 0px; position: absolute;
  19.      }
  20.      #UpdateProgress2 {
  21.       width: 200px; background-color: #FFC080; 
  22.       bottom: 0%; left: 0px; position: absolute;
  23.      }
  24.     </style>
  25. </head>
  26. <body>
  27.     <form id="form1" runat="server">
  28.         <asp:ScriptManager ID="ScriptManager1" runat="server" />
  29.         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
  30.             <ContentTemplate>
  31.                 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" />
  32.             
  33.                 <asp:Label ID="Label1" runat="server" Text="顯示數據"></asp:Label>
  34.               
  35.                 <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
  36.                 <ProgressTemplate>
  37.                  <div id="progress"><img src="img/1.gif" />
  38.                         等待中...
  39.                  </div>
  40.                 </ProgressTemplate>  
  41.                 </asp:UpdateProgress>
  42.             </ContentTemplate>
  43.         </asp:UpdatePanel>
  44.             <asp:UpdatePanel ID="UpdatePanel2" runat="server">
  45.                 <ContentTemplate>
  46.                     <asp:Button ID="Button2" runat="server" OnClick="Button2_Click1" Text="Button" /><br />
  47.                     <br />
  48.                     <asp:Label ID="Label2" runat="server" Text="顯示數據"></asp:Label>             
  49.                     <asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="UpdatePanel2">
  50.                     <ProgressTemplate>
  51.                          更新數據中....
  52.                     </ProgressTemplate>
  53.                     </asp:UpdateProgress>
  54.                 </ContentTemplate>
  55.             </asp:UpdatePanel>
  56.     </form>
  57. </body>
  58. </html>

 c#代碼:
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using System.Threading;
  11. public partial class _Default : System.Web.UI.Page 
  12. {
  13.     protected void Page_Load(object sender, EventArgs e)
  14.     {
  15.     }
  16.     protected void Button1_Click1(object sender, EventArgs e)
  17.     {
  18.         System.Threading.Thread.Sleep(3000);
  19.         Label1.Text = "刷新時間:" + DateTime.Now.ToString();
  20.     }
  21.     protected void Button2_Click1(object sender, EventArgs e)
  22.     {
  23.         System.Threading.Thread.Sleep(3000);
  24.         Label2.Text = "刷新時間:" + DateTime.Now.ToString();
  25.     }
  26. }

 其中,頁面代碼中的css是msdn上的例子。UpdatePanel1中的UpdateProgress1顯示一張動態gif圖片

補充:其實updateProgress能起到類似進度條的作用 
 
 還往大哥大姐們多多指教。
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章