473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Window.setInterval not working from asp.net

If The script below is exeuted from the onload="startit()" in the body tag everything works fine but when I remove the onload and try to execute by using the attributes.add from within the Page_Load the window.setInterval will not execute - there is no message but the timer never takes off. I put an alert in the startit() and it did appear so the attributes.add is working ok.

Would appreciate any help

thanks



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Me.Button3.Attributes.Add("onClick", "startit()")
End Sub
<SCRIPT>
function startit() {
window.setInterval("updateTime()",1000);

}
var seconds=0;

function updateTime() {

// seconds++;
var timeNow = new Date();
var hours = timeNow.getHours();
var minutes = timeNow.getMinutes();
var seconds = timeNow.getSeconds();
var timeValue = "" + ((hours >12) ? hours -12 :hours)
timeValue = ((timeValue <10)? "0":"") + timeValue
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"
document.getElementById("time").innerHTML = timeValue;
}
</SCRIPT>
</HEAD>
<body MS_POSITIONING="GridLayout" onload="startit()">
<h1>Sample Document</h1>
<h3>You have been here <b id="time">0</b> seconds.
</h3>
Nov 19 '05 #1
4 3232
I don't know what the <body> issue is, but in Page_Load try:

Page.RegisterStartupScript("mystartscript", "startit();")

-Brock
DevelopMentor
http://staff.develop.com/ballen
If The script below is exeuted from the onload="startit()" in the body
tag everything works fine but when I remove the onload and try to
execute by using the attributes.add from within the Page Load the
window.setInterval will not execute - there is no message but the
timer never takes off. I put an alert in the startit() and it did
appear so the attributes.add is working ok.

Would appreciate any help

thanks

Private Sub Page Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Me.Button3.Attributes.Add("onClick", "startit()")
End Sub
<SCRIPT>
function startit() {
window.setInterval("updateTime()",1000);
}
var seconds=0;
function updateTime() {

// seconds++;
var timeNow = new Date();
var hours = timeNow.getHours();
var minutes = timeNow.getMinutes();
var seconds = timeNow.getSeconds();
var timeValue = "" + ((hours >12) ? hours -12 :hours)
timeValue = ((timeValue <10)? "0":"") + timeValue
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"
document.getElementById("time").innerHTML = timeValue;
}
</SCRIPT>
</HEAD>
<body MS POSITIONING="GridLayout" onload="startit()">
<h1>Sample Document</h1>
<h3>You have been here <b id="time">0</b> seconds.
</h3>


Nov 19 '05 #2
I tried your suggestion and put alerts into both functions and while the
first function which has the window.setInterval showed the alert the second
function being executed from the setInterval was never executed. No errors
appear.

I also put the code into my code behind but received the same results.

thanks
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:34**********************@msnews.microsoft.com ...
I don't know what the <body> issue is, but in Page_Load try:

Page.RegisterStartupScript("mystartscript", "startit();")

-Brock
DevelopMentor
http://staff.develop.com/ballen
If The script below is exeuted from the onload="startit()" in the body
tag everything works fine but when I remove the onload and try to
execute by using the attributes.add from within the Page Load the
window.setInterval will not execute - there is no message but the
timer never takes off. I put an alert in the startit() and it did
appear so the attributes.add is working ok.

Would appreciate any help

thanks

Private Sub Page Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Me.Button3.Attributes.Add("onClick", "startit()")
End Sub
<SCRIPT>
function startit() {
window.setInterval("updateTime()",1000);
}
var seconds=0;
function updateTime() {

// seconds++;
var timeNow = new Date();
var hours = timeNow.getHours();
var minutes = timeNow.getMinutes();
var seconds = timeNow.getSeconds();
var timeValue = "" + ((hours >12) ? hours -12 :hours)
timeValue = ((timeValue <10)? "0":"") + timeValue
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"
document.getElementById("time").innerHTML = timeValue;
}
</SCRIPT>
</HEAD>
<body MS POSITIONING="GridLayout" onload="startit()">
<h1>Sample Document</h1>
<h3>You have been here <b id="time">0</b> seconds.
</h3>


Nov 19 '05 #3
Yeah, sorry. I gave you bad javascript for RegisterStartupScript:

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
this.RegisterStartupScript("MyInit", "<script>DoInit();</script>");
}
</script>
<script>
<!--
function DoInit()
{
window.setInterval('foo()', 500);
}
function foo()
{
document.getElementById('myLabel').innerHTML += 'x';
}
-->
</script>

-Brock
DevelopMentor
http://staff.develop.com/ballen
I tried your suggestion and put alerts into both functions and while
the first function which has the window.setInterval showed the alert
the second function being executed from the setInterval was never
executed. No errors appear.

I also put the code into my code behind but received the same results.

thanks
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:34**********************@msnews.microsoft.com ...
I don't know what the <body> issue is, but in Page_Load try:

Page.RegisterStartupScript("mystartscript", "startit();")

-Brock
DevelopMentor
http://staff.develop.com/ballen
If The script below is exeuted from the onload="startit()" in the
body tag everything works fine but when I remove the onload and try
to execute by using the attributes.add from within the Page Load the
window.setInterval will not execute - there is no message but the
timer never takes off. I put an alert in the startit() and it did
appear so the attributes.add is working ok.

Would appreciate any help

thanks

Private Sub Page Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Me.Button3.Attributes.Add("onClick", "startit()")
End Sub
<SCRIPT>
function startit() {
window.setInterval("updateTime()",1000);
}
var seconds=0;
function updateTime() {
// seconds++;
var timeNow = new Date();
var hours = timeNow.getHours();
var minutes = timeNow.getMinutes();
var seconds = timeNow.getSeconds();
var timeValue = "" + ((hours >12) ? hours -12 :hours)
timeValue = ((timeValue <10)? "0":"") + timeValue
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"
document.getElementById("time").innerHTML = timeValue;
}
</SCRIPT>
</HEAD>
<body MS POSITIONING="GridLayout" onload="startit()">
<h1>Sample Document</h1>
<h3>You have been here <b id="time">0</b> seconds.
</h3>


Nov 19 '05 #4
That was the answer. One thing to add. I put the RegisterStartupScript in
the button click event so it would not start automatically but wait until I
hit the button.

Thanks a lot. This really helps with understanding asp.net and javascript
relationships and using client side programming.

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:34**********************@msnews.microsoft.com ...
Yeah, sorry. I gave you bad javascript for RegisterStartupScript:

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
this.RegisterStartupScript("MyInit", "<script>DoInit();</script>");
}
</script>
<script>
<!--
function DoInit()
{
window.setInterval('foo()', 500);
}
function foo()
{
document.getElementById('myLabel').innerHTML += 'x';
}
-->
</script>

-Brock
DevelopMentor
http://staff.develop.com/ballen
I tried your suggestion and put alerts into both functions and while
the first function which has the window.setInterval showed the alert
the second function being executed from the setInterval was never
executed. No errors appear.

I also put the code into my code behind but received the same results.

thanks
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:34**********************@msnews.microsoft.com ...
I don't know what the <body> issue is, but in Page_Load try:

Page.RegisterStartupScript("mystartscript", "startit();")

-Brock
DevelopMentor
http://staff.develop.com/ballen
If The script below is exeuted from the onload="startit()" in the
body tag everything works fine but when I remove the onload and try
to execute by using the attributes.add from within the Page Load the
window.setInterval will not execute - there is no message but the
timer never takes off. I put an alert in the startit() and it did
appear so the attributes.add is working ok.

Would appreciate any help

thanks

Private Sub Page Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Me.Button3.Attributes.Add("onClick", "startit()")
End Sub
<SCRIPT>
function startit() {
window.setInterval("updateTime()",1000);
}
var seconds=0;
function updateTime() {
// seconds++;
var timeNow = new Date();
var hours = timeNow.getHours();
var minutes = timeNow.getMinutes();
var seconds = timeNow.getSeconds();
var timeValue = "" + ((hours >12) ? hours -12 :hours)
timeValue = ((timeValue <10)? "0":"") + timeValue
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"
document.getElementById("time").innerHTML = timeValue;
}
</SCRIPT>
</HEAD>
<body MS POSITIONING="GridLayout" onload="startit()">
<h1>Sample Document</h1>
<h3>You have been here <b id="time">0</b> seconds.
</h3>


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Richard A. DeVenezia | last post by:
At line this.timerId = setInterval (function(){this.step()}, 100) I get error dialog Error:Object doesn't support this property or method. If I change it to this.timerId = setInterval...
1
by: John | last post by:
Michael Winter <M.Winter@blueyonder.co.invalid> wrote in message news:<opr3wd8yvj5vklcq@news-text.blueyonder.co.uk>... > On 24 Feb 2004 14:13:47 -0800, John <johnmark@fastermail.com> wrote: > > >...
5
by: spam_me_ not | last post by:
I already understand that one cannot disable a browser's forward and back functions. This is a situation where I have code working in Mozilla V1.6 and would like something similar for Opera and...
3
by: Eli | last post by:
Hello all, I have just added a small piece of JavaScript code to a basic HTML page of mine. At the end of the page (after the closing </HTML>) I added: <SCRIPT LANGUAGE="JavaScript">...
2
by: abs | last post by:
How to detect that user started to scroll the page ? Separately vertical and horizontal scroll. Is it possible ? Regards, ABS
6
by: marktm | last post by:
Hi- I am trying to use setInterval to call a method within an object and have not had any luck. I get "Object doesn't support this property or method" when I execute the following code. What I...
3
by: shawn | last post by:
Hi All Was trying to get this bit of code working (simplified of course) for (i=0;i<uuid_num;i++) { window.setInterval(InitMap(uuidValues), timePeriod); } Where uuid_num, uuidValues,...
3
by: Josh Pencheon | last post by:
Hello. My name is Josh, from the UK. I'm 16, and having a spot of bother with some javascript I've been working on over the past few days, that gives a sliding menu. <html> <head> <script...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.