Solved

asp problem with delay before redirect

Posted on 2006-11-01
7
1,006 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 52

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 52

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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…
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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