Calling a JS function in .NET

Reply Forum
Forum postIkurro @ 2008-08-04 18:40:36
ReplyReply to
hi, i want to call a javascript function every 5 seconds, so i followed the Timer Control example. This JS function has to update the position of some items into a google map. I've tried to do it this way but i get an error:

......
<script type="text/javascript">
function MyJSFunction(){}
</script>
......
<asp:Timer runat="server" id="UpdateTimer" interval="5000" ontick="MyJSFunction()" />
<asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional">
.....

Any idea about how to do it? Thanks

PD: sry for my english :P


Forum postBrianHjoellund @ 2008-08-06 17:49:15
ReplyReply to
Try this:
<script type="text/javascript">
function MyJSFunction(){}

window.onload = function() { setInterval(MyJSFunction, 5000); }
</script>

setInterval will continue to execute MyJSFunction every 5 seconds. If you need some way to stop it, try this:

<script type="text/javascript">

function MyJSFunction() { }

function stopInterval()
{
clearInterval(id);
}

window.onload = function()
{
id = setInterval(MyJSFunction, 5000);
}

</script>











© net-tutorials.com 2006 - 2012

MailContact net-tutorials.com