0

Ajax 面板在功能 C# ASP.net 站点中间更新。

这是按钮单击。我想在函数的其余部分继续之前将 LbError.Text 更新为 "" 。这是我当前的代码。

   protected void BUpload_Click(object sender, EventArgs e)
        {
            LbError.Text = "";

            UpdatePanel1.Update(); //// need it to update here before it moves on 
                                   but it waits till the end to update the lablel
        Exicute functions.....
        .......
        .......
        }





<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<contenttemplate> 
<asp:Label ID="LbError" runat="server" CssClass="failureNotification" Text=""></asp:Label>
<br /><br />
<br /><br />
    <asp:TextBox ID="NewData" runat="server"></asp:TextBox><br />
    then click
    <asp:Button ID="BUpload" runat="server" Text="Upload New Data" 
        onclick="BUpload_Click"/><br />

我尝试过的事情包括另一个 UpdatePanel 和相同的结果。任何帮助将不胜感激。

4

1 回答 1

1

您可以使用 PageRequestManager 来完成这项工作。这是工作示例。标记:

<asp:ScriptManager ID="sm" runat="server" />
        <script type="text/javascript">
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.add_initializeRequest(InitializeRequest);
            function InitializeRequest(sender, args) {
                $get('LbError').textContent = '';
            }
        </script>
        <asp:Label ID="LbError" runat="server" CssClass="failureNotification" Text="This is a label"></asp:Label>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <br />
                then click
                <asp:Button ID="BUpload" runat="server" Text="Upload New Data"
                    OnClick="BUpload_Click" /><br />

                <asp:Label ID="Label1" runat="server" CssClass="failureNotification" Text=""></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>

以及 C# 背后的代码:

protected void BUpload_Click(object sender, EventArgs e)
{
    UpdatePanel1.Update(); 
    System.Threading.Thread.Sleep(5000);
    Label1.Text = "Done";
}
于 2013-10-23T03:50:18.290 回答