Solved

asp problem with delay before redirect

Posted on 2006-11-01
7
995 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 50

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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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 50

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
currencylayer API intergrate to ASP 25 71
Dreamweaver server behavior gone 6 136
Voice recognition ASP or ASP.NET or JavaScript 2 68
ASP SQL Syntax Duplicate Key 7 102
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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