ASP.NET: Ajax UpdatePanel Issue

2019-08-22 17:31发布

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... Please help asap.

1条回答
登录 后发表回答