Monday, March 26, 2012

Updating progress ?

Hi!

Is it possible to write such page that will be updating [rendering] itself during some long running process ?
For example:

void ExecuteLongRunning()
{

for(int i=0; i < 50 ; i++){
RenderSomeText();
Thread.Sleep(10000);

}

}

I'd like to see the text after each execution of RenderSomeText is it possible and how to do it :)

Jarod

I think it is possible to implement it. Here are some sample codes for your reference.
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lblUpdateProgress" runat="server" Text="This is a asp:UpdateProgress testing"></asp:Label>
<asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnUpdate" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<span style="display: block;">
<asp:UpdateProgress ID="UpdateProgressOne" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/airplane.bmp" />
</ProgressTemplate>
</asp:UpdateProgress>
</span>
</div>

Behind Codes:

protected void btnUpdate_Click(object sender, EventArgs e)
{
???for(int i=0; i < 50 ; i++){
???RenderSomeText();
???Thread.Sleep(10000);
???}
}

Wish the above can help you.

I'll use your example :) To show you what I really need so take a look at implementation of my RenderSomeText()

protected

void btnUpdate_Click(object sender,EventArgs e)

{

for (int i = 0; i < 50; i++)

{

RenderSomeText();

Thread.Sleep(10000);

}

}

privatevoid RenderSomeText()

{

lblUpdateProgress.Text +=

DateTime.Now.ToString();

lblUpdateProgress.Text =

"\r\n";

}

What I want to see on a page is updated "label" every time I press a button. So right after RenderSomeText() executes. My friend told me how to get such result using asynchronous delegate invocation. But maybe there is a better way of doing it ?

Jarod


I can't continue to help you for business.Try to post your issues with a new thread.This may?be?better?for you?to?solve?this?issue.

No comments:

Post a Comment