Welcome Guest Search | Active Topics | Sign In | Register

Not clear about using progress bar Options
PC
Posted: Saturday, June 6, 2009 11:43:31 PM
Rank: Newbie
Groups: Member

Joined: 6/6/2009
Posts: 2
My user control ascx file has this code:

<%@ Control Language="C#" AutoEventWireup="false" CodeBehind="HandleFiles.ascx.cs" Inherits="GRIS_Ajax.HandleFiles" %>
<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>


<table border=2 bordercolor=gray width=800>

<tr bordercolor=white>
<td style="width: 566px" colspan=2>
<asp:Button ID="Upload1" runat="server" Text="Upload" OnClick="Upload1_Click" Width=105px ToolTip="Upload file button" />&nbsp;
<asp:Button ID="Button_CancelUpload" runat="server" Text="Cancel Upload" Width="98px" /></td>
</tr>

<tr>
<td>
<eo:ProgressBar runat="server" id="ProgressBar1" ShowPercentage="True" IndicatorImage="00060104"
BackgroundImageRight="00060103" ControlSkinID="None" BackgroundImage="00060101" IndicatorIncrement="7"
BackgroundImageLeft="00060102" Width="300px" StartTaskButton="Upload1" StopTaskButton="Button_CancelUpload" Visible=true>
</eo:ProgressBar>
</td>
</tr>

</table>

=======================================================
code behind file (JUST LIST RELATED METHODS):

protected void Upload1_Click(object sender, EventArgs e)
{
//If doing UploadNow in the method ProgressBar1_RunTask, do nothing here, correct?
UploadNow();
}

private void UploadNow()
{
//do something here, which takes long time to perform (e.g., 90 seconds).
}

override protected void OnInit(EventArgs e)
{

InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.ProgressBar1.RunTask += new EO.Web.ProgressTaskEventHandler(this.ProgressBar1_RunTask);
this.Load += new System.EventHandler(this.Page_Load);

}

private void ProgressBar1_RunTask(object sender, EO.Web.ProgressTaskEventArgs e)
{
e.UpdateProgress(0);

for (int i = 0; i < 100; i++)
{
//Stop the task as soon as we can if the user has
//stopped it from the client side
if (e.IsStopped)
break;

//Here we call Thread.Sleep just for demonstration
//purpose. You should replace this with code that
//performs your long running task.
System.Threading.Thread.Sleep(500);

//Should I use UploadNow method to replace "System.Threading.Thread.Sleep(500)"?
//UploadNow();

//You should frequently call UpdateProgress in order
//to notify the client about the current progress
e.UpdateProgress(i);
}

e.UpdateProgress(100);
}

==============================================================
My purpose is show progress status on the progress bar after click the button Upload1 (as soon as clicking the Upload1 button, the long run method UploadNow will start). Now, I don't understand the meaning of "You should replace this with code that performs your long running task" in the method ProgressBar1_RunTask. Should I replace "System.Threading.Thread.Sleep(500)" with UploadNow and doing nothing in Upload1_Click? or do something else?

Thanks

PC
eo_support
Posted: Sunday, June 7, 2009 8:24:47 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You should no longer have Uploader1_Click (Uploader1_Click will not be called at all). You would set the ProgressBar's StartButton to Uploader1 and then only handle the ProgressBar1_RunTask.

You would replace everything inside RunTask with your UploadNow method. The code inside RunTask is just to give you an example of how your UploadNow (or whatever other method you would like to show progress information) should look like. That means inside your UploadNow you should call e.UpdateProgress to update the progress. ProgressBar does not generate progress information on its own. So when you are 30% done, you tell ProgressBar (by calling e.UpdateProgress) that you are 30% done, when you are 50% done, you tell ProgressBar that you are 50% done, etc.

Thanks!
PC
Posted: Monday, June 8, 2009 2:53:09 PM
Rank: Newbie
Groups: Member

Joined: 6/6/2009
Posts: 2
Thanks for the instruction. I have a further question: let's say inside the UploadNow method, there are two sequential sub processes:

1. Upload files: loop through all collected files and put every file to a directory folder called FileStorage.
2. Compress the folder FileStorage and ship the .zip file to somewhere.

Now, I want the progress bar firstly shows acting on the process 1 with text "Upload is being processed" and the progress percentage (1 - 100%). Once the process 1 is done, the progress bar will show a new text "Compression is being processed" and the progress percentage (1-100%).

Can the progress bar control can do the tasks described above?

PC
eo_support
Posted: Monday, June 8, 2009 3:02:15 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You can do that except you can not move the ProgressBar to 100% while you are in "upload is being processed" statge. The basic rules are:

1. You can move the ProgressBar whatever way you want (for example, first 10%, then 20%, then back to 15%, the forward to 30%), except for;
2. Once you move to 100%, you can not move back;

So I would suggest you update your first run to somewhere close to done (for example, 80% or 90%), then move it ack to 0% and start the second run.

The status text has no such restrictions. You can pass whatever to the client side.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.