Q:

Ajax panel update during the middle of a function

Ajax panel update during the middle of a function C# ASP.net site.
This is the button click. I would like to update LbError.Text to ""
before the rest of the function continues. 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. Any help would be greatly appreciated.

A:

You can use PageRequestManager to do the job. 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#:
protected void BUpload_Click(object sender, EventArgs e)
{
    UpdatePanel1.Update(); 
    System.Threading.Thread.Sleep(5000);
    Label1.Text = "Done";
}

