ASP.NET AJAX UpdateProgress控制項概述

來源:互聯網
上載者:User

方案

當網頁包含一個或多個用於部分頁呈現的 UpdatePanel 控制項時,UpdateProgress 控制項可協助您設計更為直觀的 UI。如果部分頁更新速度較慢,則可以使用 UpdateProgress 控制項來提供有關更新狀態的可視反饋。可以在頁上放置多個 UpdateProgress 控制項,其中每個控制項都與不同的 UpdatePanel 控制項相關聯。也可以使用一個 UpdateProgress 控制項,並將其與頁上的所有 UpdatePanel 控制項關聯。

背景

UpdateProgress 控制項將呈現一個 <div> 元素,該元素將根據關聯的 UpdatePanel 控制項是否已導致非同步回傳來顯示或隱藏。對於初始頁呈現和同步回傳,將不會顯示 UpdateProgress 控制項。

將 UpdateProgress 控制項與 UpdatePanel 控制項關聯

通過設定 UpdateProgress 控制項的 AssociatedUpdatePanelID 屬性,可將 UpdateProgress 控制項與 UpdatePanel 控制項關聯。當回傳事件來源自 UpdatePanel 控制項時,將顯示任何關聯的 UpdateProgress 控制項。如果不將 UpdateProgress 控制項與特定的 UpdatePanel 控制項關聯,則 UpdateProgress 控制項將顯示任何非同步回傳的進度。

如果將一個 UpdatePanel 控制項的 ChildrenAsTriggers 屬性設定為 false,並且非同步回傳源自該 UpdatePanel 控制項內部,則將顯示任何關聯的 UpdateProgress 控制項。

建立 UpdateProgress 控制項的內容

可使用 ProgressTemplate 屬性以聲明方式指定由 UpdateProgress 控制項顯示的訊息。<ProgressTemplate> 元素可包含 HTML 和標記。下面的樣本示範如何為 UpdateProgress 控制項指定訊息。

<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
  An update is in progress...
</ProgressTemplate>
</asp:UpdateProgress>

下面的樣本示範一個 UpdateProgress 控制項,該控制項顯示兩個 UpdatePanel 控制項的更新狀態。

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
   Protected Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)
     System.Threading.Thread.Sleep(3000)
   End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head 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" />
   <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
   <ContentTemplate>
   <%=DateTime.Now.ToString() %> <br />
   <asp:Button ID="Button1" runat="server" Text="Refresh Panel" OnClick="Button_Click" />
   </ContentTemplate>
   </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">
   <ProgressTemplate>
    Update in progress...
   </ProgressTemplate>
   </asp:UpdateProgress>
   </div>
   </form>
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.