Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is there a way for SPLongOperation not to redirect the page, but only to hide the processing bar? My scenario is that, when I open a modal dialog, I want to show a loading/processing information to the user.

My sample code:

protected void Page_Load(object sender, EventArgs e)
{ 
   using (SPLongOperation lo = new SPLongOperation(Page)) 
   {
      lo.Begin();
      // Load information
      //lop.End(Request.Url.AbsolutePath, SPRedirectFlags.Default, Context, null);
   }
}

Has anyone an idea how to accomplish something like that?

share|improve this question
1  
Maybe you could consider using an ajax call instead of a postback. You could use jQuery or any ajax framework to call the server without leaving the page, while display a html pseudo-modal div. –  Steve B May 31 '12 at 13:16
add comment

3 Answers 3

It sounds like what you want is to have the end user perform a long running operation, and then update the current page (without making a full page request) with the results of that long running query. The SPLongOperation does a somewhat simplified version of this without implementing the full pattern. (Essentially the only thing it lets you do when the task completes is redirect, but it still has the client page do something when a long running server task finishes, which is no trivial task.)

Here is an example of the more generalized case. It demonstrates creating a page, starting an asynchronous task on the server, and then updating the client page (using AJAX, meaning without a full page reload) with the results of that asynchronous task. It can be used to update as you go (i.e. a progress bar) and/or when you're done (with the final results).

It's worth mentioning that you are fighting against the nature of HTTP and the standard browser framework to do this. Since you need to send a request to the client to give them an initial page, you force the client code to continually poll the server essentially asking "Are you done yet?", "Are you done yet?", or possibly, "What's your progress now?", "What's your progress now?" This can add up to a lot of network traffic which can put a strain on both the client, and the server, so it probably shouldn't be used for very, very long running tasks, or on pages that will have a lot of users. (It does seem quite slick when you get it working though ;)

share|improve this answer
add comment

I did the same sometime ago. Pseudo code:

  • Check if data is in my cache (cache duration max 1 minute)
  • If yes: load the page normally and show the data
  • If no: use SPLongOperation to show the progress while loading the data in the background then write it to my cache.
  • lo.End with redirect to the same page

With SPLongOperation I think there is no other way. However, if you try to do this within a modal dialog I think it wouldn't work, because the redirect is executed by the browser for the entire page.

share|improve this answer
add comment

A simple way I have been able to make work in a custom form is below.

protected void Page_Load(object sender, EventArgs e)
{ 
   using (SPLongOperation operation = new SPLongOperation(Page)) 
   {
      operation.Begin();

      // Do stuff here...

      operation.EndScript("window.location = window.location");
   }
}
share|improve this answer
    
That still refreshes the page though doesn't it? –  Paul Lucas Mar 12 at 2:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.