Asp.net 用UpdateProgress載入資料顯示進度條

來源:互聯網
上載者:User

背景:在做asp.net項目時,遇到頁面開啟載入資料的時候,如果資料載入過慢,就會導致頁面出現空白,在網上也尋找了一些資料,都是用的js類比的,尋找了一陣子,未果。

所以自己思考了下,自己寫了個。

實現原理:

頁面中添加一個UpdatePanel,裡面添加updateProgress,並在這裡添加載入時候的動畫頁面,在updatePanel裡面添加一個按鈕,類比點擊事件。暈了,快說不明白了,直接上代碼吧,代碼如下:

前台代碼:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DevDetailPage.aspx.cs"    Inherits="ManageService.DevDetailPage" %><!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">    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />    <title></title>        <link href="Styles/StyleSheet.css" rel="stylesheet" type="text/css" />    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>        <style type="text/css">        body        {            margin: 0;            padding: 0;        }               #upLoading{height:2px}            </style> <script type="text/javascript">     window.onload = function () {         $("#LoadData").click();     } </script></head><body>        <form id="form1" runat="server">    <asp:ScriptManager ID="ScriptManager1" runat="server">    </asp:ScriptManager>    <asp:UpdatePanel ID="upLoading" runat="server">    <ContentTemplate>          <asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="upLoading">              <ProgressTemplate>                <img src="Images/loadinfo.gif" />正在載入資料...              </ProgressTemplate>         </asp:UpdateProgress>        <asp:Button ID="LoadData" runat="server" Text="Button" onclick="LoadData_Click" style="display:none"/>    </ContentTemplate>      </asp:UpdatePanel>    <asp:UpdatePanel ID="UpdatePanel1" runat="server">        <ContentTemplate>            <div id="allData" runat="Server" visible="false">                   編寫控制項綁定資料            </div>        </ContentTemplate>    </asp:UpdatePanel>    </form></body></html>

後台代碼:

 protected void LoadData_Click(object sender, EventArgs e)        {                        if (Request.QueryString.Count > 0)            {               //綁定資料                BindData();                allData.Visible = true;            }        }

總結:一句話就是在在updatePanel裡面添加按鈕,在載入的時候執行按鈕事件擷取資料,

覺得這種方法還是不大好,如有更好的方法請說下

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.