ASP.NET: Ajax UpdatePanel Issue

北城以北 提交于 2019-12-25 02:24:49

问题


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:


these might help you:

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

ASP.NET Asynchronous label update



来源:https://stackoverflow.com/questions/12720666/asp-net-ajax-updatepanel-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!