This is a migrated thread and some comments may be shown as answers.

RadProgressArea Help

4 Answers 177 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Han
Top achievements
Rank 1
Han asked on 18 Jan 2012, 06:22 PM
Hi,

Can you show me how to use RadProgressArea while loading data from a sql server?  Here is my scenario:

I have a RadButton.  when a user click on this button, I have a function call RetrieveData() and this function will connect to a sql database and query about 100,000 records and performing a lot of data manipulation so it will take awhile to produce desire data.

while processing the data, I would like to display like a progress bar so user can see what's going on and wait.  I found the demo here:
http://demos.telerik.com/aspnet-ajax/upload/examples/customprogress/defaultcs.aspx and really like it, but I don't know how to apply it to my scenario.  From the example, it sets the total process = 100, but in my case, my query run can take up to 3 minutes.  Please provide code as possible.  Here is my code behind page:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Do not display SelectedFilesCount progress indicator.
            RadProgressArea1.ProgressIndicators &= ~ProgressIndicators.SelectedFilesCount;
        }
  
        RadProgressArea1.Localization.Uploaded = "Total Progress";
        RadProgressArea1.Localization.UploadedFiles = "Progress";
        RadProgressArea1.Localization.CurrentFileName = "Please wait while updating database... ";
    }

protected void RetrieveData()
{
        //using LINQ to SQL to select data
}

private void UpdateProgressContext()
    {
  
        RadProgressContext progress = RadProgressContext.Current;
  
        const int total = 100;
  
        progress.Speed = "N/A";
        for (int i = 0; i < total; i++)
        {
            progress.PrimaryTotal = 1;
            progress.PrimaryValue = 1;
            progress.PrimaryPercent = 100;
  
            progress.SecondaryTotal = total;
            progress.SecondaryValue = i;
            progress.SecondaryPercent = i;
  
            progress.CurrentOperationText = "Step " + i.ToString();
  
            if (!Response.IsClientConnected)
            {
                //Cancel button was clicked or the browser was closed, so stop processing
                break;
            }
  
            progress.TimeEstimated = (total - i) * 100;
             
            //Stall the current thread for 0.1 seconds
            System.Threading.Thread.Sleep(50);
        }
    }

protected void RadButton1_Click(object sender, EventArgs e)
   {
       UpdateProgressContext(); //I assume this is how it call
       RetrieveData();
   }
Please help, thanks in advance!

4 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 19 Jan 2012, 03:52 PM
Hi Han,

RadProgressArea has to be updated manually. It has no way of knowing how long a method or operation is going to take. So the only way to reflect your database retrieval progress, is to update the ProgressContext from inside your RetreaveData function.
 
Regards,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Han
Top achievements
Rank 1
answered on 19 Jan 2012, 04:16 PM
Hello Bozhidar,
 
Thank you for your reply.  Please be more detail on the ProgressContext is place inside the RetrieveData function.  Is the following code right?

protected void RetrieveData()
{
   //Using LIN to SQL to select data 
      
    RadProgressContext progress = RadProgressContext.Current;
  
    const int total = 100;
  
    for (int i = 0; i < total; i++)  
    {  
        progress.PrimaryTotal = 1;  
        progress.PrimaryValue = 1;  
        progress.PrimaryPercent = 100;  
        progress.SecondaryTotal = total;
        progress.SecondaryValue = i;
                progress.SecondaryPercent = i;  
        progress.CurrentOperationText = "Step " + i.ToString();
  
        if (!Response.IsClientConnected)  
        {
                      //Cancel button was clicked or the browser was closed, so stop processing   
            break;
        }
  
    progress.TimeEstimated = (total - i) * 100;
  
    //Stall the current thread for 0.1 seconds
    System.Threading.Thread.Sleep(50);  
}
0
Bozhidar
Telerik team
answered on 19 Jan 2012, 05:41 PM
Hi Han,

I don't think you understood me. I'll try to be more specific.

The progress that you see on the screen in the ProgressArea, is only updated inside the for loop. There you set explicitly the number of "transferred items", the number of "remaining items", the remaining time etc. Any actions or methods outside the loop won't register in the ProgressArea. To update it, you have to set all the properties manually at equal (if possible) intervals. 

I'll try to explain it with an example. Say you have a method that goes through a list of integer numbers and adds their sum. Here's how you can monitor the process of this method:

aspx.
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <div>
             
        <asp:button ID="buttonSubmit" runat="server" Text="Calculate Sum" OnClick="buttonSubmit_Click" CssClass="RadUploadButton" />
        <asp:Label Text="Result: " runat="server" ID="Label1" />
        <asp:Label Text="" runat="server" ID="Label2" />
             
        <telerik:RadProgressManager id="Radprogressmanager1" runat="server" />
             
        <telerik:RadProgressArea id="RadProgressArea1" runat="server" />
 
    </div>
    </form>
</body>
</html>

cs.
private static Random rand = new Random();
List<int> numbers = new List<int>();
 
protected void Page_Load(object sender, System.EventArgs e)
{
    for (int i = 0; i < 400; i++)
    {
        numbers.Add(rand.Next(0, 400));
    }
 
    RadProgressArea1.Localization.Uploaded = "Total Progress";
    RadProgressArea1.Localization.UploadedFiles = "Progress";
    RadProgressArea1.Localization.CurrentFileName = "Custom progress in action: ";
}
 
protected void buttonSubmit_Click(object sender, System.EventArgs e)
{
    Label2.Text = SumNumbers(numbers).ToString();
}
 
private int SumNumbers(List<int> numbers)
{
    int total = numbers.Count;
    int sum = 0;
 
    RadProgressContext progress = RadProgressContext.Current;
    progress.Speed = "N/A";
 
    for (int i = 0; i < total; i++)
    {
        sum += numbers[i];
 
        progress.PrimaryTotal = 1;
        progress.PrimaryValue = 1;
        progress.PrimaryPercent = 100;
 
        progress.SecondaryTotal = total;
        progress.SecondaryValue = i;
        progress.SecondaryPercent = (i*100)/total;
 
        progress.CurrentOperationText = "Step " + i.ToString();
 
        if (!Response.IsClientConnected)
        {
            //Cancel button was clicked or the browser was closed, so stop processing
            break;
        }
 
        progress.TimeEstimated = (total - i) * 100;
        //Stall the current thread for 0.1 seconds
        System.Threading.Thread.Sleep(30);
    }
    return sum;
}

Please note that the updating of the process happens inside the monitored method itself.
 
Regards,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Han
Top achievements
Rank 1
answered on 19 Jan 2012, 05:56 PM
Thank you for your detail explaination.  So there is no way for me to use this control that would apply to my scenario.

Han
Tags
Ajax
Asked by
Han
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Han
Top achievements
Rank 1
Share this question
or