• 0

[ASP.net C#] Sending output suring processing


Question

In a nutshell this is what im trying to do:

I have a, ASP.net page which does some processing that takes a few seconds to complete. During processing I dont want the user to click back, forward, refresh, etc. I also want to avoid pop up's and iframes, because Browser compatability is very important.

So I figure the best way to do this is when the program loads, before anything at all happens, I want the text "Now Processing, please wait" to be sent and displayed in the browser. After processing is completed I'd like the text "Processing Done! Click here to continue" sent to the browser.

The page code will be somthing like this:

// Display first message
Response.Write( "Please wait while we process your request." );

// Do the processing which might take 10 seconds
...........
A FEW HUNDRED LINES OF CODE HERE
...........

// Processing Complete, display the rest of the page
Response.Write( "Processing Completed! Click here to continue!" );

I have thought about the problem myself and I realise that the best solution is to set "Response.Buffer" to false, and in theory the page should output to the browser as the page processes, rather then do all processing and output one huge chunk of HTML at the end of processing.

Unfortunatley it isnt working, even if I use "Resonse.Flush()" the page will still output everything at the end of processing, and it isn't doing the user any good telling them to "Please Wait" after they have already waited.

Can anyone please tell me what im doing wrong? Or perhaps give me a hint on what to do?

This used to work in classic ASP, but obviously in ASP.net things are different.

Thanks.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Check out Scott Guthrie's tips and tricks for ASP.NET from the ASP.NET Roadshow.

http://www.scottgu.com

This snippet of code is pretty cool. Just set your please wait page, and your redirect page in the BeginPageLoad function. Set the events for the Body's onload, and onunload events.

 <script language="javascript">

  var iLoopCounter = 1;
  var iMaxLoop = 6;
  var iIntervalId;
  
  function BeginPageLoad() {
      frame1.document.location = "PleaseWait.htm";
 	 location.href = Result.aspx;
 	 iIntervalId = window.setInterval("iLoopCounter=UpdateProgressMeter(iLoopCounter, iMaxLoop)", 500);
  }

  function EndPageLoad() {
 	 window.clearInterval(iIntervalId);
 	 ProgressMeter.innerText = "Page Loaded -- Not Transferring";
  }

  function UpdateProgressMeter(iCurrentLoopCounter, iMaximumLoops) {
  
 	 iCurrentLoopCounter += 1;
 	 
 	 if (iCurrentLoopCounter <= iMaximumLoops) {
    return iCurrentLoopCounter;
 	 }
 	 else {
    return 1;
 	 }
  }

  </script>

<body onload="BeginPageLoad()" onunload="EndPageLoad()">

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.