Solved

asp problem with delay before redirect

Posted on 2006-11-01
7
993 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
ID: 17856463
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
ID: 17856499
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
ID: 17856531
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:hungxadieu
ID: 17856593
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
ID: 17856616
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
ID: 17856621
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
ID: 17856642
>>if I use scriptTimeout, I think my code will never run.
that's not true..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Replacing smart quotes from word 7 67
Response.Flush in Classic ASP causing TIME_WAIT ports 9 83
UTC (timezone) without using an API 16 39
Error viewing ASP page 12 146
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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/…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

10 Experts available now in Live!

Get 1:1 Help Now