0

I am supposed to update the progress & display the corresponding message on the client side while the function is still under execution at server side.

How can I achieve this?

The function looks like:

protected void Button1_Click(object sender, EventArgs e)
        {
            string Result = "Success";
            if (Result == "Success")
            {
                Label1.Text = "Plan mst Completed";
                Thread.Sleep(2000);     //Some functionality here
                Label1.Text = "Packing date mst Started";
            }
            if (Result == "Success")
            {
                Label1.Text = "Packing date mst Completed";
                Thread.Sleep(2000);     //Some functionality here
                Label1.Text = "Etd mst Started";
            }

            if (Result == "Success")
            {

                Label1.Text = "Etd mst Completed";
                Thread.Sleep(2000);     //Some functionality here
                Label1.Text = "Inner box mst Started";

            }
        }

And I have to update the text of Label1 while the above function is still under execution.

I have tried using AJAX (although I'm still a beginner), but with no success. Here's what I did:

<form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server" Interval="10" ontick="Timer1_Tick1">
            </asp:Timer>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

        </ContentTemplate>
    </asp:UpdatePanel>
    </form>

And the corresponding events:

protected void Page_Load(object sender, EventArgs e)
        {
            UpdatePanel1.UpdateMode = UpdatePanelUpdateMode.Conditional;
        }
        protected void Timer1_Tick1(object sender, EventArgs e)
        {
            UpdatePanel1.Update();            
        }

Any other alternatives other than AJAX such as via jQuery or otherwise are also welcome.

halfer
  • 19,824
  • 17
  • 99
  • 186
Viral Jain
  • 1,004
  • 1
  • 14
  • 30

1 Answers1

1

these might help you:

http://forums.asp.net/t/1500201.aspx

ASP.NET Asynchronous label update

Community
  • 1
  • 1
Talha Ashfaque
  • 3,656
  • 1
  • 15
  • 7