Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1014905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:19:20+00:00 2026-05-16T10:19:20+00:00

I want to provide status updates during a long-running task on an ASP.NET WebForms

  • 0

I want to provide status updates during a long-running task on an ASP.NET WebForms page with AJAX.

Is there a way to get the ScriptManager to execute and process a script for a web service request concurrently with an async postback?

I have a script on the page that makes a web service request. It runs on page load and periodically using setInterval(). It’s running correctly before the async postback is initiated, but it stops running during the async postback, and doesn’t run again until after the async postback completes.

I have an UpdatePanel with a button to trigger an async postback, which executes the long-running task. I also have an instance of an AJAX WCF Web service that is working correctly to fetch data and present it on the page but, like I said, it doesn’t fetch and present the data until after the async postback completes.

During the async postback, the long-running task sends updates from the page to the web service.

The problem is that I can debug and step through the web service and see that the status updates are correctly set, but the updates aren’t retrieved by the client script until the async postback completes.

It seems the Script Manager is busy executing the async postback, so it doesn’t run my other JavaScript via setInterval() until the postback completes.

Is there a way to get the Script Manager, or otherwise, to run the script to fetch data from the WCF web service during the async postback?

I’ve tried various methods of using the PageRequestManager to run the script on the client-side BeginRequest event for the async postback, but it runs the script, then stops processing the code that should be running via setInterval() while the page request executes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:19:21+00:00Added an answer on May 16, 2026 at 10:19 am

    A follow-up with a solution for anyone that may find this in the future.

    I tried sending the request in a multitude of ways:

    • The AJAX script objects created when you add the WCF service as a ServiceReference to the ScriptManager. So, if the WCF service class is ProgressService with a GetProgress method, I created a new ProgressService object in JavaScript and called progressService.GetProgress().
    • An XmlHttpRequest request.
    • A jQuery $.getJson() request.
    • A Sys.Net.WebRequest request.
    • A Sys.Net.WebServiceProxy request.

    It turns out that even if the client request is sent, i.e., not buffered by the ASP.NET ScriptManager, that the WCF service won’t respond if it is part of the same website in IIS.

    So rather than creating an entirely separate WCF project, and an entirely separate IIS website, I switched to a traditional ASP.NET (SOAP) web service (.asmx).

    I was able to keep the .asmx service part of the same project in Visual Studio, and website in IIS. The request is sent during a postback, and the service responds during a postback.

    After adding it as a ServiceReference under the ScriptManager, I was also able to use essentially the same scripting objects, creating a new ProgressWebService(), then calling progressWebService.GetProgress(). A callback handler passed to GetProgress() then handles the response and updates the UI.

    Web service:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Web.Caching;
    
    namespace MyNamespace
    {
        public class Progress
        {
            public string Message { get; set; }
            public bool Complete { get; set; }
        }
    
        [WebService(Namespace = "MyNamespace")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        [System.Web.Script.Services.ScriptService]
        public class ProgressWebService : System.Web.Services.WebService
        {
            protected static Dictionary<string, Progress> ProgressMessages = new Dictionary<string, Progress>();
    
            [WebMethod]
            public Progress GetProgress(string progressId)
            {
                return ProgressMessages.ContainsKey(progressId) ? ProgressMessages[progressId] : new Progress();
            }
    
            [WebMethod]
            public void SetProgress(string progressId, string progress, bool complete)
            {
                if (ProgressMessages.ContainsKey(progressId))
                {
                    ProgressMessages[progressId].Message = progress;
                    ProgressMessages[progressId].Complete = complete;
                }
                else
                    ProgressMessages.Add(progressId, new Progress() { Message = progress, Complete = complete });
            }
    
            [WebMethod]
            public void SetProgressComplete(string progressId, bool complete)
            {
                if (ProgressMessages.ContainsKey(progressId))
                    ProgressMessages[progressId].Complete = complete;
                else
                    ProgressMessages.Add(progressId, new Progress() { Complete = complete });
            }
    
            [WebMethod]
            public void AddProgress(string progressId, string progress)
            {
                if (ProgressMessages.ContainsKey(progressId))
                    ProgressMessages[progressId].Message += progress;
                else
                    ProgressMessages.Add(progressId, new Progress() { Message = progress });
            }
        }
    }
    

    Client side:

    <%@ Page language="c#" CodeFile="About.aspx.cs" Inherits="MyNamespace.About" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <script type="text/javascript">
            var ProgressServiceInterval; // global interval var, so it can be set and cleared across functions
    
            function btnBackup_Click(sender, e) {
                sender.disabled = true; // disable the backup button, so the request isn't duplicated
                // start getting the backup progress from the web service
                var progressService = new MyNamespace.ProgressWebService();
                progressService.SetProgressComplete('<%= strBackupProgressGuid %>', false, null, null, null);
                ProgressServiceInterval = setInterval('setBackupProgress()', 1000); // get progress once per second
            }
    
            function setBackupProgress() {
                var progressService = new MyNamespace.ProgressWebService();
                progressService.GetProgress('<%= strBackupProgressGuid %>', progressCallback, null, null);
            }
    
            function progressCallback(result) {
                var txtBackupOutput = $get('<%= txtBackupOutput.ClientID %>');
                try {
                    // show the progress message
                    txtBackupOutput.value = result.Message; 
                    // stop checking if progress is complete
                    if (result.Complete == true) clearInterval(ProgressServiceInterval);
                    // scroll the textarea to the bottom
                    txtBackupOutput.scrollTop = txtBackupOutput.scrollHeight - txtBackupOutput.clientHeight;
                } catch (ex) {
    
                }
            }
        </script>         
    </head>
    <body>
        <form id="frmMyForm" method="post" runat="server">
            <ajaxToolkit:ToolkitScriptManager runat="Server" EnablePartialRendering="true" EnablePageMethods="true" ID="ScriptManager1" >
                <Services>
                    <asp:ServiceReference Path="ProgressWebService.asmx" />
                </Services>
            </ajaxToolkit:ToolkitScriptManager>
    
            <asp:UpdatePanel ID="updBackup" runat="server" RenderMode="Inline">
                <ContentTemplate>
                    <asp:UpdateProgress ID="updBackupProgress" AssociatedUpdatePanelID="updBackup" runat="server" DynamicLayout="false">
                        <ProgressTemplate>
                            <div style="text-align:center;margin-bottom:-32px;"> 
                                <img src="loading.gif" alt="Loading..." />
                            </div>
                        </ProgressTemplate>
                    </asp:UpdateProgress>
    
                    <asp:Button ID="btnBackup" runat="server" CssClass="SubmitButton" Text="Back Up Data" UseSubmitBehavior="false" OnClientClick="btnBackup_Click(this, event);" />
                    <br /><br />
    
                    <asp:TextBox ID="txtBackupOutput" runat="server" ReadOnly="true" TextMode="MultiLine" Rows="10" Width="100%" Wrap="true" />  
    
                </ContentTemplate>
            </asp:UpdatePanel>
        </form>
    </body>
    </html>
    

    And the server-side:

    namespace MyNamespace
    {
        public partial class About
        {
            protected string strBackupProgressGuid
            {
                get
                {
                    if (Session["strBackupProgressGuid"] == null)
                        Session["strBackupProgressGuid"] = Guid.NewGuid().ToString();
                    return Session["strBackupProgressGuid"] as string;
                }
            }
    
            ProgressWebService _progressService;
            protected ProgressWebService progressService
            {
                get
                {
                    return _progressService = _progressService ?? new ProgressWebService();
                }
            }
    
           void btnBackup_Click(object sender, EventArgs e)
            {
                progressService.SetProgress(strBackupProgressGuid, "Started\r\n", false);
                System.Threading.Thread.Sleep(10000);
                progressService.AddProgress(strBackupProgressGuid, "+10\r\n");
                System.Threading.Thread.Sleep(10000);
                progressService.AddProgress(strBackupProgressGuid, "+20\r\n");
                System.Threading.Thread.Sleep(10000);
                progressService.AddProgress(strBackupProgressGuid, "+30\r\n");
    
                progressService.SetProgressComplete(strBackupProgressGuid, true);
            }
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net page that calls a dll that will start a long
I want to provide silverlight app to my customer while hosting the app at
I want to provide a piece of Javascript code that will work on any
I want to provide dynamic download of files. These files can be generated on-the-fly
If I want to provide OpenID as the only registration method available AND want
Say you have an app, that you want to provide users ability to browse
I want to use RSpec mocks to provide canned input to a block. Ruby:
I want to have the context menu of links provide me an option to
I want to create a right click context menu for my textboxes to provide
I want to answer questions about data in Erlang: count things, correlate messages, provide

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.