ProgressArea will not get updated from WebMethod

1 posts, 0 answers
  1. Ingemar
    Ingemar avatar
    17 posts
    Member since:
    Apr 2012

    Posted 08 Jul Link to this post

    I seem to have problems using a RadProgressArea together with a webservice method called from client side.

    If I on the other hand use a code behind function as the way of updating the progress, the updating of the progress works.
    Why?
    I will start with describing the working approach with code behind and then the client side calling a webservice approach.

     

    Working setup
    In the webpage, I have a telerik:RadProgressArea and a RadProgressManager:

    <telerik:RadProgressArea ID="progressArea"
      ProgressIndicators="TotalProgressBar,TotalProgressPercent" Skin="Metro"
      HeaderText="Please wait!" runat="server"/>
     <telerik:RadProgressManager ID="progressManager" runat="server"/>

     

    I also have an asp:Button like:

    OnClick="Button1_Click"

    In that code behind eventhandler I perform a lot of work. It has a loop where it performs some tasks. Before the loop, I have this code:

    var progress = RadProgressContext.Current;
     var num = 0;
     var maxnum = tasks.Count();
     
     progress.PrimaryPercent = 0;
     progress.PrimaryValue = 0;
     progress.PrimaryTotal = maxnum;

    After every task, in other words in the end of the loop, I update PrimaryPercent and PrimaryValue like:

    num++;
    progress.PrimaryPercent = num * 100 / maxnum;
    progress.PrimaryValue = num;

    and after that loop, the eventhandler ends with

    rapMain.ResponseScripts.Add("CloseWindow()");

    and that javascript function closes the window.
    This setup works, the progressbar gets updated as it should.

    Here is the a response to Telerik.RadUploadProgressHandler.ashx?RadUrid=22b0e25c-69c9-4be7-8d7e-33b818854f35&RadUploadTimeStamp=1467900709164&:

    var rawProgressData = {InProgress:true,ProgressCounters:true,PrimaryPercent:'81',PrimaryValue:'111',PrimaryTotal:'136'};

     

    The non working setup (using a WebService)
    I have an aspx file with an identical setup as in the working case.

    I call the web method with javascript:

    var progressBar = $find(progressAreaId);
    progressBar.show();
     
    var pm = getRadProgressManager();
    pm.startProgressPolling();
     
    $.ajax({
      type: "POST",
      url: "Foobar.asmx/Methodname",
      data: {id:2343},
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg)
      {
        progressBar.hide();
        alert("done!");
      }
    });

    (If I do not call pm.startProgressPolling, the ashx will not be called frequently to get the progress values).

    The web method looks like this:

    [WebMethod(EnableSession = true)]
    public bool MethodName(int id)
    {
        var progress = RadProgressContext.Current;
     
        /* some code that retrieves an array of tasks */
     
        var maxnum = tasks.Count;
        progress.PrimaryPercent = 0;
        progress.PrimaryValue = 0;
        progress.PrimaryTotal = maxnum;
     
        foreach (var task in tasks)
        {
            /* code that performs task */
            result++;
     
            progress.PrimaryPercent = result * 100 / maxnum;
            progress.PrimaryValue = result;
        }
     
       return true;
    }

    It seems like RadProgressContext.Current contains the expected data. If I manipulate RadProgressContext.Current.CurrentOperationText in the code behind (in Page_Load), the web service will be able to read that string.

    However, the progress will never be updated and then the web service method has run, the progressbar will dissapear as it should.

    The polling will not get the expected data but say that InProgress is false.
    Here is the a response to Telerik.RadUploadProgressHandler.ashx?RadUrid=a1dcfc89-bd8c-43d3-b88f-718890d7fc04&RadUploadTimeStamp=1467898578437&:

    var rawProgressData = {InProgress:false,ProgressCounters:false};


    This is a copy of a stackoverflow posting at http://stackoverflow.com/questions/38248183/progressarea-will-not-get-updated-from-webmethod

    Also it is a copy of the forum posting http://www.telerik.com/forums/progressarea-will-not-get-updated-from-webmethod that I posted in the wrong forum topic.

Back to Top