【问题标题】:UpdateProgress not working on initial page loadUpdateProgress 在初始页面加载时不起作用
【发布时间】:2014-02-18 15:06:51
【问题描述】:

我需要做什么才能使我的 updatePanel 中的 UpdateProgress 在初始页面加载时显示?在您对同一页面上的更新面板等中的网格进行排序后,它工作正常,但在初始页面加载时却没有。我能做些什么?这是我的代码示例。我的代码隐藏中没有任何代码,所以这可能是我不确定的一些问题。

<asp:UpdateProgress ID="updProgress"
AssociatedUpdatePanelID="UpdatePanel1"
runat="server">
    <ProgressTemplate>
        <div id="postback-loader">
         <img src="Images/ajax-loader-blue.gif" style="margin:11px auto;display:block;" /><br />
         <asp:Label ID="Label1" runat="server" Text="Loading Computers..." Width="170px"></asp:Label>
        </div>                   
    </ProgressTemplate>
</asp:UpdateProgress>

【问题讨论】:

  • 在页面加载期间是否绑定了所有数据?如果是这样,您的更新进度将永远不会显示,因为它会在显示您的页面和更新进度之前获取所有数据。

标签: asp.net updatepanel updateprogress


【解决方案1】:

您需要将控制权返回给页面,然后执行部分回发以使用 jQuery 初始化回发来更新 UpdatePanel 的内容。

这是我拼凑的一个简单示例:

标记

<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            __doPostBack('<%=UpdatePanel1.ClientID %>');
        });
    </script>
    <form id="form1" runat="server">
    <div>
    </div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel1_Load">
        <ContentTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
        <ProgressTemplate>
            <div id="postback-loader">
                <img src="Images/ajax-loader-blue.gif" style="margin: 11px auto; display: block;" /><br />
                <asp:Label ID="Label1" runat="server" Text="Loading Computers..." Width="170px"></asp:Label>
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
</form>

代码背后

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
        TextBox1.Text = "First Load";
}

protected void UpdatePanel1_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        Thread.Sleep(10000);
        TextBox1.Text = "Finished";
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多