Solved

setInterval isnt working reliably for asp.net application

Posted on 2006-07-19
7
315 Views
Last Modified: 2012-08-13
I have some code as follows:
My goal is to have a timer in java script that does some periodic checks and submits the form.  I have used some alerts to see if my javascript is working.  THe first time I tried the code below I got an alert window every second.  But sadly, re reunning I dont see any alerts at all.  If I lower the timeout i might get one alert.

I tried changing the alert to document.Form1.submit(); since that is what i ultimately want, but I dont see a form submission either.  the html for the page:
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">


The working c# code:  (at least I get my alert if its added to check()
              if(!Page.IsPostBack)
               {
                    SubmitButton.Attributes.Add("onclick","check();");
               }

The not working very well javascript:
function check(){
     setInterval("checkStatus()",1000)
}
function checkStatus(){
     alert('checkfile');
}
0
Comment
Question by:lynx2sw1
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:FDzjuba
ID: 17142151
use
setTimeout("doForwardStep()", 2000);

instead of
setInterval("doForwardStep()", 2000);


0
 
LVL 7

Expert Comment

by:FDzjuba
ID: 17142167
and to get repeatative timers  call timer function from initialize function again like this,

function checkStatus(){
     alert('checkfile');
     check();
}
0
 
LVL 1

Author Comment

by:lynx2sw1
ID: 17142303
Modified as per below.  I get a few form submissions , maybe 5, and then no more.
Do I need to be clearing and resetting something?
var t
var count=0;
function check(){
      setTimeout("checkStatus()",2000);
}
function checkStatus(){
      document.Form1.submit();
      check();
}
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.

 
LVL 7

Expert Comment

by:FDzjuba
ID: 17142462
is your page reloading, then stick the setTimeout in the body of the document which will trigger itself everytime the page is reloaded, no need for functions.

0
 
LVL 1

Author Comment

by:lynx2sw1
ID: 17142707
well, the real goal is to periodically do a test, and only reload when the test indicates.
0
 
LVL 10

Accepted Solution

by:
eguilherme earned 500 total points
ID: 17229611
i suggest sticking with setInterval, but i suggest aswell clearing ur interval before anything

var intervalID
function check(){
     intervalID = setInterval("checkStatus()",1000)
}
function checkStatus(){
    if(whatIwant==true)
    {
        clearInterval(intervalID)

    }
}

0
 
LVL 1

Author Comment

by:lynx2sw1
ID: 17373380
oops.  I meant to award FDZJuba.  
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
jQuery scrollTop 2 41
how can display objects ? 3 25
Full Screen problem when auto scale IFRAME 2 65
Split in Javascript 5 31
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 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

22 Experts available now in Live!

Get 1:1 Help Now