C# 如何使用 UpdateProgress Control 来显示等待符号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12191436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 22:25:10  来源:igfitidea点击:

How I can use the UpdateProgress Control to show a wait symbol?

c#asp.netlistviewupdateprogress

提问by Tarasov

I have an ASP.NET application with a ListView. I get data from Active Directory and now I want a wait symbol for the time if the ListVewis building. I thought I would use a UpdateProgressControl from Ajax Control toolkit. But I don't know how I can use it if I click on a Button and the wait symbol (for example a gif) closes if the ListViewis finished. :(

我有一个带有ListView. 我从 Active Directory 获取数据,现在如果ListVew正在构建,我想要一个等待时间的符号。我想我会使用UpdateProgressAjax Control 工具包中的 Control。但是我不知道如果我单击按钮并且等待符号(例如 gif)在ListView完成后关闭,我该如何使用它。:(

My CS file:

我的CS文件:

protected void btnBenutzerSuchen_Click(object sender, EventArgs e)
{
     //If I click on this Button the gif must start

    try
    {
        ... // my ListView get data

        this.myListView.DataSource = dv; 
        this.myListView.DataBind();

        ...

    }
    catch (Exception)
    {
        ...
    }

   //If the ListView is finish the gif must close 
}

How I can do this? Can I do this with the UpdateProgresslike this:

我怎么能做到这一点?我可以这样做UpdateProgress

<asp:UpdateProgress ID="UpdateProgress1" DynamicLayout="true" runat="server" AssociatedUpdatePanelID="?" >
    <ProgressTemplate>
    <div class="progress">
        <img src="images/ajax-loader-arrows.gif" />&nbsp;please wait...
    </div>
    </ProgressTemplate>
</asp:UpdateProgress>

My update.aspx file:

我的 update.aspx 文件:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="~/BenutzerListe.aspx.cs" Inherits="BenutzerListe.BenutzerListe" %>
<%@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%>

<!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 src="Scripte/jquery-1.7.2.js" type="text/javascript"></script>
    <script type="text/javascript" src="Scripte/jquery-ui-1.8.22.custom.min.js" ></script>

    <script language="javascript" type="text/javascript">

// my javascript code

    </script>

     <link href="~/App_Theme/BenutzerListeStyle.css" type="text/css" rel="Stylesheet" />
     <link href="App_Theme/jquery-ui-1.8.22.custom.css" type="text/css" rel="Stylesheet" />
     <link href="App_Theme/PopUpDialog_Style.css" type="text/css" rel="Stylesheet" />

    <style type="text/css">
        #SuchTabelle
        {
            width: 587px;
        }
    </style>

</head>

<body>
    <form id="form1" runat="server">

    <asp:scriptmanager id="ScriptManager1" runat="server">
       </asp:scriptmanager> 

           <div class="header">
           <br />

        <table id="SuchTabelle" class="SuchTabelle" runat="server" border="0" width="100%">
            <tr>
                <th><asp:Label ID="id_SearchUser" runat="server" Text="lblSearchUser"></asp:Label></th>
                <th class="txtBenutzerSuchen"><asp:TextBox ID="txtBenutzer"  runat="server" Width="150px" ToolTip="Gesucht wird nach Vorname, Nachname, eMail , Abteilung und Telefonnummer"></asp:TextBox></th>
                <th><asp:Label ID="id_location" runat="server" Text="lblLocation"></asp:Label></th>
                <th class="DropDownList"><asp:DropDownList ID="dropWerk" runat="server" Width="200px" /></th>
                <th>

                        <asp:Button  ID="Button2" runat="server" Text="Suchen" onclick="btnBenutzerSuchen_Click" Width="150px"/>

                </th>
            </tr>
        </table>

      </div>

           <div class="bodyList">

           <asp:UpdatePanel ID="update" runat="server">
            <ContentTemplate>

                <asp:ListView> .... </asp:ListView>

            </ContentTemplate>
           </asp:UpdatePanel>

           <asp:UpdateProgress ID="updatePro" DynamicLayout="true" runat="server" AssociatedUpdatePanelID="update">
            <ProgressTemplate>
               <asp:Image ImageUrl="~/App_Theme/ajax_loader_circle.gif" runat="server" ID="waitsymbol" />
            </ProgressTemplate>
           </asp:UpdateProgress>

        <hr />
    </div>

    </form>
</body>
</html>

采纳答案by Waqar Janjua

First place your listview aspx code inside an update panel

首先将您的列表视图 aspx 代码放在更新面板中

<asp:UpdatePanel ID="up" runat="server">
    <ContentTemplate>
        // Place your list View Code here
        <asp:ListView ..........
         ...... </asp:ListView>
    </ContentTemplate>
    <Triggers>
       // If button is present outside update panel then specify AsynPostBackTrigger
       <asp:AsyncPostBackTrigger ControlID="btnControlID" EventName="Click" /> 
    </Triggers>
</asp:UpdatePanel>

// Now Set AssociatedUpdatePanelID="up" in the UpdateProgress

<asp:UpdateProgress ID="UpdateProgress1" DynamicLayout="true" runat="server"  AssociatedUpdatePanelID="up" >
<ProgressTemplate>
<div class="progress">
    <img src="images/ajax-loader-arrows.gif" />&nbsp;please wait...
</div>
</ProgressTemplate>
</asp:UpdateProgress>

回答by xiaosu

Try to put your button within an UpdatePanel that contains the code may take a long time to execution, then associate the UpdateProgress control to the UpdatePanel. Code you may need is just like:

尝试将您的按钮放在包含可能需要很长时间执行的代码的 UpdatePanel 中,然后将 UpdateProgress 控件关联到 UpdatePanel。您可能需要的代码如下:

<asp:UpdatePanel ID="updatePanelMain" runat="server">
<ContentTemplate>
    <asp:button runat="server" ID="btnBenutzerSuchen" OnClick="btnBenutzerSuchen_Click"/>
</ContentTemplate>
</asp:UpdatePanel>

<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="updatePanelMain" DisplayAfter="200">
<ProgressTemplate>
    <div class="progress">
        <img src="images/ajax-loader-arrows.gif" />&nbsp;please wait...
    </div>
</ProgressTemplate>
</asp:UpdateProgress>

回答by Pilgerstorfer Franz

I did a small example simulation a button click within an updatePanel. Pay attention to the attribute AssociatedUpdatePanelIDwhich must be set, in order to show your progressTemplate.

我做了一个小例子模拟在 updatePanel 中单击按钮。注意AssociatedUpdatePanelID必须设置的属性,以显示您的 progressTemplate

default.aspx

默认.aspx

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
    <asp:Button ID="btnDoSomething" runat="server" Text="Do Something" 
        onclick="btnDoSomething_Click" />
    <asp:ListView> YOUR_LISTVIEW_GOES_HERE </asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>

<asp:UpdateProgress ID="UpdateProgress1" DynamicLayout="true" runat="server"
                    AssociatedUpdatePanelID="UpdatePanel1">
    <ProgressTemplate>
        <div class="progress">
            <img src="images/ajax-loader-arrows.gif" />&nbsp;please wait...
        </div>
    </ProgressTemplate>
</asp:UpdateProgress>

default.aspx.cs

默认.aspx.cs

protected void btnDoSomething_Click(object sender, EventArgs e)
{
    System.Threading.Thread.Sleep(5000);
    // or update listView
}

回答by Kamal Pratap

Show Progress Bar Using UpdateProgress Control in Asp.net

在 Asp.net 中使用 UpdateProgress 控件显示进度条

Refer This Link for more information

有关更多信息,请参阅此链接

http://www.freshcodehub.com/Article/22/show-progress-bar-using-updateprogress-control-in-aspnet

http://www.freshcodehub.com/Article/22/show-progress-bar-using-updateprogress-control-in-aspnet

<asp:UpdateProgress ID="prgLoadingStatus" runat="server" DynamicLayout="true">
        <ProgressTemplate>
            <div id="overlay">
                <div id="modalprogress">
                    <div id="theprogress">
                        <asp:Image ID="imgWaitIcon" runat="server" ImageAlign="AbsMiddle" ImageUrl="~/img/progress.gif"
                            Width="230px" /><br />
                        Please wait...
                    </div>
                </div>
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Button ID="btnProgress" runat="server" Text="Show Progress" OnClick="btnProgress_Click" />            
        </ContentTemplate>
    </asp:UpdatePanel>