简体   繁体   English

在功能中间进行Ajax面板更新

[英]Ajax panel update during the middle of a function

Ajax panel update during the middle of a function C# ASP.net site. 在C#ASP.net功能站点的中间进行Ajax面板更新。

This is the button click. 这是单击按钮。 I would like to update LbError.Text to "" before the rest of the function continues. 我想在其余功能继续之前将LbError.Text更新为“”。 This is my current code. 这是我当前的代码。

   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 />

Things I have tried include have another UpdatePanel just and same results. 我尝试过的事情包括拥有另一个UpdatePanel,并且结果相同。 Any help would be greatly appreciated. 任何帮助将不胜感激。

You can use PageRequestManager to do the job. 您可以使用PageRequestManager来完成这项工作。 Here's working sample. 这是工作示例。 Markup: 标记:

<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>

And code behind C#: 和C#背后的代码:

protected void BUpload_Click(object sender, EventArgs e)
{
    UpdatePanel1.Update(); 
    System.Threading.Thread.Sleep(5000);
    Label1.Text = "Done";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM