views:

50

answers:

2

Hi everyone

I have an ASP.NET (C#) page that has a long load time (like 2 minutes). The user is presented with a little animation and a "please wait" message. If the user accidentally loads this page, they need to wait for it to load.

My question is: Is there a way to stop the page load?

Thank you

A: 

Try window.stop() in JavaScript.

Brandon Satrom
I tried that and it does not stop the page from rendering
Galael
Are you in IE? Try this: `document.execCommand('Stop')`. Not pretty, but if that works, you'll probably need to support both commands across different browsers.
Brandon Satrom
@Brandon Satrom: If you look at the reply to my comment on the question this isn't quite what is needed anyway. Galael wnats a way to stop the server processing from happening as well which a pure JS solution I dont' think ever will.
Chris
@Chris. Good point. Right you are.
Brandon Satrom
+2  A: 

If you want to stop the server side processing then its a tricky operation. Generally once a request is made that page is rendering on its own independant of other thigns going on. What you would probably need to do is re-engineer that page to check at regular intervals whether a stop command has been issued and abort whatever it is doing at that point. The stop flag could be put in session and should be cleared out after the stoppage.

You may also need to consider how to properly identify the right one to stop (in case there is more than one running). This could be done by returning a unique ID that can be used in part of a call to the "abort" page.

My approach though rather than this complciated rigmarole is to make efforts to stop the user from making this accident. Possibly make whatever link they are clicking pop up an alert saying "the following page will take several minutes to render, do you wish to continue" and then hopefully you will effectively be aborting the page request before it is even made.

I should note that I've never tried to do this sort of thing before so there may be easier ways to do it but this is how I'd probably think abotu going about the problem.

Chris
Your idea seems good. I'll give it a try
Galael