Solved

asp problem with delay before redirect

Posted on 2006-11-01
7
991 Views
Last Modified: 2008-01-09
I want my page to show the information and after a few seconds it redirect to another page. I have the following code in jscripts try to solve the problem:


<%
Response.Write("my information");
Response.Buffer=true;

function Delay(DelaySecond)
{
      var SecCount=0;
      var Sec2=0;
      var d=new Date();
      var Sec1;
      while(SecCount<DelaySecond + 1)
      {
            Sec1=d.getSeconds();
            if(Sec1!=Sec2)
            {
                  Sec2=d.getSeconds();
                  SecCount+=1;
            }
      }
}
      Delay(10);
      Response.Redirect("index.asp");
%>

and here is the error:
Active Server Pages, ASP 0113 (0x80004005)
The maximum amount of time for a script to execute was exceeded. You can change this limit by specifying a new value for the property Server.ScriptTimeout or by changing the value in the IIS administration tools.

How can I solve this problem, I appreciate any idea that can solve the idea.
0
Comment
Question by:hungxadieu
7 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
try add this on top of your page?

Server.ScriptTimeOut = 10000; //where the figure need to be quite big

More info on Server.ScriptTimeOut property, you can refer to:
http://www.w3schools.com/asp/prop_scripttimeout.asp

hope this helps
0
 
LVL 6

Accepted Solution

by:
Dragonlaird earned 400 total points
Comment Utility
The problem is simply, you're running the delay on the server instead of delaying on the browser. Thus, the server is correctly running through your loop and waiting for it to finish but in the meantime, the ASP timeout limit has been reached and hence, the page is abandoned.

Try writing your code to run the JavaScript loop on the client instead.

<%
Response.Write("my information");
Response.Buffer=true;
%>
<script type="text/javascript">
var DelaySecs = 5
var Sec1 = setTimeout("reDirect();",DelaySecs*1000);
function reDirect() {
      clearTimeout(Sec1);
      top.window.location = 'index.asp';
};
</script>
<%
    Response.Flush
%>
0
 
LVL 5

Expert Comment

by:ddelhez
Comment Utility
Hello

you should change your code to
function Delay(DelaySecond)
{
     var SecCount=0;
     var Sec2=0;
     var d=new Date();
     var Sec1;
     Sec1 = d.getSeconds();
     Sec2 = Sec1 + 1;
     while(SecCount<DelaySecond + 1)
     {
          if(Sec1==Sec2)
          {
               Sec2=Sec1 + 1;
               SecCount+=1;
          }
          Sec1=d.getSeconds();
     }
}


cause you loop indefinitely in your Delay function
and there are too many cases where your use of getSeconds function use could be wrong...
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:hungxadieu
Comment Utility
to ryancys: if I use scriptTimeout, I think my code will never run.
to Dragonlaird: Thanks for your help, it works.
0
 
LVL 6

Expert Comment

by:Dragonlaird
Comment Utility
Another point to note:

Using Response.Buffer above means the server will buffer all the content and only send the entire output to the client when the page is complete (e.g. after your loop is finished).

Hence, your first line:
Response.Write("my information");

Will not be sent to the client until the last possible moment, the same moment the browser is told to redirect...

Hence, your intention to display your message for a few seconds before redirecting the client won't work as the message will appear very briefly (after the delay) before redirecting to the new page.

Using the client-loop method above will display the intended message, then delay the redirect for a few seconds and will deliver your required result.

There is one small thing to mention, since I tend to develop ASP using VBSCRIPT, not JavaScript, there is a possibility the server could attempt to execute the code embedded in the <SCRIPT></SCRIPT> section above instead of sending the tags and code to the client, if this occurs, write the tags to the client using:

Response.Write "<script type=""text/javascript"">";
...Code here...
Response.Write "</script>";
0
 
LVL 6

Expert Comment

by:Dragonlaird
Comment Utility
Since I submitted by last post after you closed the question, ignore my last post lol... Glad it worked..
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
>>if I use scriptTimeout, I think my code will never run.
that's not true..
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now