Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

asp problem with delay before redirect

Posted on 2006-11-01
7
Medium Priority
?
1,077 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 53

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 1600 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
Independent Software Vendors: 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 53

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

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

604 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