I Have Label And Button In One UpdatePanel ,Now I call Long Process with ForEach Loop On Button Click What I want is to Update Text Of Label after Completion Of Loop.Is there any Easy Way to Change Text Of Label At runtime.I heard Something that we can do this with Iframe But I dont have any idea about that.
CODE
aspx
<asp:UpdatePanel ID="UpdatePanelUpdate" runat="server" UpdateMode="Conditional"> <ContentTemplate>
<div>
<asp:Button ID="ButtonUpdate" runat="server" Text="Update"
onclick="ButtonUpdate_Click" />
<br />
<br />
<asp:Label ID="LabelUpdateCount" runat="server" Text=""></asp:Label>
< /div>
</ContentTemplate>
</asp:UpdatePanel>
aspx.cs
protected void ButtonUpdate_Click(object sender, EventArgs e)
{
int count = 0;
foreach()
{
do my stuff();
count = count + 1;
LabelUpdateCount.Text = count.ToString();
}
}
SO,I want to show change of label at runtime…..
If I get it right, the server returns only after the method is completed but you want the client side label to display the current completed item count while it’s being done.
I would like to mentions an issue with it. Each post back will take roughly around 200-400ms so it won’t be updated any sooner. I strongly suggest consider updating every once in a while than trying to update for every job completed.
To accomplish this you have to run your function loop on a different thread (have it modify a variable). Add have the client check its status using js timer(return the value of the variable).
In other words what you are trying to do is to show progress to the client. In which case the following link might be useful.
Real-Time Progress Bar With ASP.NET AJAX
Note: it returns percentage. You can change it such a way to have it return the count.
The above link is taken from the below question. It is in many ways related issue.
ASP.NET AJAX Progress Bar: Update from Code Behind?