I was
thinking if there is a way to stop/start ASP.NET 2.0 AJAX 1.0 Timer control from client side, regarding that, I found 2 methods
_startTimer() and _stopTimer(), those were excatly what I was looking for.
bellow is a sample client code of how you can use these 2 methods:
function startTimer()
{ var timer =
$find("<%=ajaxTimer.ClientID%>")
timer._startTimer();
}
function stopTimer()
{ var timer =
$find("<%=ajaxTimer.ClientID%>")
timer._stopTimer();
}
The above code assuming that you have an AJAX Timer control on the page named ajaxTimer.
Call these method from your client side code, or add them as event handlers on your target elements.
I don't know why these are not documented, or we are not supposed to use them?! Actually I don't know.
I thought that after using these methods the browser will cause a problem regarding client scripts, but both Opera and IE worked just fine without any problem. Also I didn't notice any slow down or hanging in both browsers.
I cannot for the life of me figure out what I am doing wrong. Every time I use the $find shortcut I get a null reference to my timer object. I have tried everything I can think of, but nothing seems to work. Basically I have two divs, only one of which
I want to show. If the user has Silverlight installed, I want to show it, and hide the "non-silverlight" div... and vice versa if no silverlight is detected. The non-silverlight div is a rotator that switches images and content on the timer tick. I want
to stop the timer if silverlight is detected, however the $find just isn't finding the timer as in your post. Any ideas?
BTW - I have tried using the ClientID as in "var timer = $find('<%=tmAjaxTimer.ClientID%>');" but this is not a masterpage or control so it should be able to pull it without this... but doesn't.
Here is my update panel code and javascript:
<asp:UpdatePanel ID="upHeadImage" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="tmAjaxTimer" runat="server" Interval="1000" OnTick="AjaxTimer_Tick" />
<div id="Head_Silverlight" runat="server" visible="true">
<object width="950" height="325"
data="data:application/x-silverlight-2,"
type="application/x-silverlight-2" >
<param name="source" value="HomePageV2.xap"/>
</object>
</div>
<div id="Head_Image" runat="server" style="background-image: url('Styles/Images/Silverlight/Explorer_Static.jpg');" visible="true">
<div style="float: right; width: 475px; height: 261px; margin-right: 50px;">
<div style="margin: 20px 20px 0px 20px; overflow: auto; text-align: left;">
<div id="divExplorerContent" runat="server" visible="false">
<div class="Row">
<span style="font: bold 12pt Georgia; color: #000;">Discover Our New Medicare Advantage Explorer + Rx PPO Plan</span>
<div class="ListLinks">
<ul>
<li style="margin-bottom: 2px; font: 10pt Verdana; color: #000;">Out-of-network doctors throughout the U.S. are covered</li>
<li style="margin-bottom: 2px; font: 10pt Verdana; color: #000;">$0 copay for preventive care and clearly defined copays for office visits and hospitalization</li>
<li style="margin-bottom: 2px; font: 10pt Verdana; color: #000;">In-network coverage in Central Oregon, Palm Springs or Phoenix</li>
<li style="font: 10pt Verdana; color: #000;">You are covered worldwide for urgent and emergency care</li>
</ul>
</div>
</div>
</div>
<div id="divNaturalContent" runat="server" visible="false">
<div class="Row">
<span style="font: bold 12pt Georgia; color: #000;">Holistic Health Insurance That Focuses On The Body-Mind-Spirit Connection</span>
<p style="font: 10pt Verdana; color: #000;">Our new Natural Health Plan is specially designed with an emphasis on naturopathic medicine, chiropractic, acupuncture, massage therapy, nutraceuticals (vitamins and minerals), and includes conventional medical benefits.</p>
</div>
</div>
<div id="divHealthyKidsContent" runat="server" visible="true">
<div class="Row">
<span style="font: bold 12pt Georgia; color: #000;">Every Kid In Oregon Should Be A Healthy Kid!</span>
<p style="font: 10pt Verdana; color: #000;">Depending on family income, children may be eligible for free or low-cost health coverage for doctor visits, dental care, vision, medicines and more through the Clear One Healthy KidsConnect program. Your child must have been without health insurance for two months (though there are exceptions to this rule for special circumstances, like a parent’s job loss or a child’s serious medical need). Child must be under the age of 19.</p>
</div>
</div>
</div>
</div>
<div style="clear: both;"></div>
<div style="float: left; width: 950px; height: 62px; margin-top: 2px; margin-left: 30px; text-align: left;">
<div style="float: left;">
<div class="Row">
<span style="font: bold 10pt Verdana; color: #ececec; margin-bottom: 0px;">Travel Freely</span>
</div>
<div class="Row">
<span style="font: bold 10pt Verdana; color: #aaa; margin-bottom: 0px;">Holistic Health Insurance</span>
</div>
<div class="Row">
<span style="font: bold 10pt Verdana; color: #FFF; margin-bottom: 0px;">Every Kid Should Be Healthy!</span>
</div>
</div>
<div style="float: right;">
<div class="Row">
<asp:LinkButton ID="lnkPrevious" runat="server" OnCommand="SwitchPane" CommandArgument="Previous">Previous</asp:LinkButton>
<asp:LinkButton ID="lnkStop" runat="server" OnCommand="SwitchPane" CommandArgument="Pause">Pause</asp:LinkButton>
<asp:LinkButton ID="lnkPlay" runat="server" OnCommand="SwitchPane" CommandArgument="Play">Play</asp:LinkButton>
<asp:LinkButton ID="lnkNext" runat="server" OnCommand="SwitchPane" CommandArgument="Next">Next</asp:LinkButton>
</div>
</div>
</div>
</div>
</ContentTemplate>
<Triggers>
<%--<asp:AsyncPostBackTrigger ControlID="tmStartupTimer" EventName="Tick" />--%>
<asp:AsyncPostBackTrigger ControlID="tmAjaxTimer" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<script type="text/javascript">
var browser = navigator.appName;
var SLInstalled = false;
if (browser == 'Microsoft Internet Explorer')
{
try
{
var slControl = new ActiveXObject('AgControl.AgControl'); //IE
SLInstalled = true;
}
catch (e)
{
SLInstalled = false;
}
}
else
{
try
{
if (navigator.plugins["Silverlight Plug-In"]) // Other Than IE
{
SLInstalled = true;
}
}
catch (e)
{
SLInstalled = false;
}
}
document.getElementById('hdSilverlightInstalled').value = SLInstalled;
if (SLInstalled == true) {
Hide('<%= Head_Image.ClientID %>');
stopTimer();
}
else {
Hide('<%= Head_Silverlight.ClientID %>');
}
function Hide(id) {
if (document.getElementById) {
obj = document.getElementById(id);
if (obj.style.display == "none") {
obj.style.display = "";
}
else {
obj.style.display = "none";
}
}
}
function stopTimer() {
var timer = $find('tmAjaxTimer');
//Sys.Debug.trace(timer.get_interval());
timer._stopTimer();
}
</script>
Thanks!
Matt
EDIT: Of course I find the solution a few minutes after I post this... If anyone else has the same issue I had to make sure I was not calling my stopTimer function until the DOM had been fully loaded. I used the following script at the end of my page to accomplish this:
<script type="text/javascript">
// Detect DOM ready... if ready, call stop timer function
function pageLoad()
{
stopTimer();
}
</script>
mosessaur
Contributor
2214 Points
353 Posts
ASP.NET 2.0 AJAX Timer Hacks! How to Stop/Start ASP.NET AJAX Timer Clinet Side
Apr 03, 2007 05:09 PM|LINK
I was thinking if there is a way to stop/start ASP.NET 2.0 AJAX 1.0 Timer control from client side, regarding that, I found 2 methods _startTimer() and _stopTimer(), those were excatly what I was looking for.
bellow is a sample client code of how you can use these 2 methods:
function startTimer()
function stopTimer(){
var timer = $find("<%=ajaxTimer.ClientID%>")
timer._startTimer();
}
{
var timer = $find("<%=ajaxTimer.ClientID%>")
timer._stopTimer();
}
The above code assuming that you have an AJAX Timer control on the page named ajaxTimer.
Call these method from your client side code, or add them as event handlers on your target elements.
I don't know why these are not documented, or we are not supposed to use them?! Actually I don't know.
I thought that after using these methods the browser will cause a problem regarding client scripts, but both Opera and IE worked just fine without any problem. Also I didn't notice any slow down or hanging in both browsers.
Hope you find it useful.
AJAX Timer Control ASP.NET ASP.NET AJAX
Software Engineer
robertmazzo
Participant
1030 Points
347 Posts
Re: ASP.NET 2.0 AJAX Timer Hacks! How to Stop/Start ASP.NET AJAX Timer Clinet Side
Apr 11, 2008 06:38 PM|LINK
I think you hit the proverbial "jackpot" with those client-side functions. Thank you !
It appears that you found that on the DotNetSlackers.com website. Rock on !
Bob
dpooja85
Member
21 Points
27 Posts
Re: ASP.NET 2.0 AJAX Timer Hacks! How to Stop/Start ASP.NET AJAX Timer Clinet Side
Jul 23, 2009 08:56 PM|LINK
Why am I getting a "null is null or not an object" error when i use this $find??? :(
RemithR
Contributor
2376 Points
396 Posts
Re: ASP.NET 2.0 AJAX Timer Hacks! How to Stop/Start ASP.NET AJAX Timer Clinet Side
Jul 23, 2009 09:03 PM|LINK
Good One.... Thank you
ashish-1983
Contributor
4879 Points
1257 Posts
Re: ASP.NET 2.0 AJAX Timer Hacks! How to Stop/Start ASP.NET AJAX Timer Clinet Side
Dec 07, 2009 08:21 AM|LINK
you are master blaster.
this thing is awesome man..!
Gridview
Jquery
Asp.net
Fun !
ewerton.sc
Member
12 Points
15 Posts
Re: ASP.NET 2.0 AJAX Timer Hacks! How to Stop/Start ASP.NET AJAX Timer Clinet Side
Jan 13, 2010 06:56 PM|LINK
It works fine
Thanks !
Ewerton Luis de Mattos
A Brazilian developer with a bad English :)
mlapora
Member
2 Points
1 Post
Re: ASP.NET 2.0 AJAX Timer Hacks! How to Stop/Start ASP.NET AJAX Timer Clinet Side
Mar 12, 2010 04:21 AM|LINK
Hello,
I cannot for the life of me figure out what I am doing wrong. Every time I use the $find shortcut I get a null reference to my timer object. I have tried everything I can think of, but nothing seems to work. Basically I have two divs, only one of which I want to show. If the user has Silverlight installed, I want to show it, and hide the "non-silverlight" div... and vice versa if no silverlight is detected. The non-silverlight div is a rotator that switches images and content on the timer tick. I want to stop the timer if silverlight is detected, however the $find just isn't finding the timer as in your post. Any ideas? BTW - I have tried using the ClientID as in "var timer = $find('<%=tmAjaxTimer.ClientID%>');" but this is not a masterpage or control so it should be able to pull it without this... but doesn't.
Here is my update panel code and javascript:
<asp:UpdatePanel ID="upHeadImage" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Timer ID="tmAjaxTimer" runat="server" Interval="1000" OnTick="AjaxTimer_Tick" /> <div id="Head_Silverlight" runat="server" visible="true"> <object width="950" height="325" data="data:application/x-silverlight-2," type="application/x-silverlight-2" > <param name="source" value="HomePageV2.xap"/> </object> </div> <div id="Head_Image" runat="server" style="background-image: url('Styles/Images/Silverlight/Explorer_Static.jpg');" visible="true"> <div style="float: right; width: 475px; height: 261px; margin-right: 50px;"> <div style="margin: 20px 20px 0px 20px; overflow: auto; text-align: left;"> <div id="divExplorerContent" runat="server" visible="false"> <div class="Row"> <span style="font: bold 12pt Georgia; color: #000;">Discover Our New Medicare Advantage Explorer + Rx PPO Plan</span> <div class="ListLinks"> <ul> <li style="margin-bottom: 2px; font: 10pt Verdana; color: #000;">Out-of-network doctors throughout the U.S. are covered</li> <li style="margin-bottom: 2px; font: 10pt Verdana; color: #000;">$0 copay for preventive care and clearly defined copays for office visits and hospitalization</li> <li style="margin-bottom: 2px; font: 10pt Verdana; color: #000;">In-network coverage in Central Oregon, Palm Springs or Phoenix</li> <li style="font: 10pt Verdana; color: #000;">You are covered worldwide for urgent and emergency care</li> </ul> </div> </div> </div> <div id="divNaturalContent" runat="server" visible="false"> <div class="Row"> <span style="font: bold 12pt Georgia; color: #000;">Holistic Health Insurance That Focuses On The Body-Mind-Spirit Connection</span> <p style="font: 10pt Verdana; color: #000;">Our new Natural Health Plan is specially designed with an emphasis on naturopathic medicine, chiropractic, acupuncture, massage therapy, nutraceuticals (vitamins and minerals), and includes conventional medical benefits.</p> </div> </div> <div id="divHealthyKidsContent" runat="server" visible="true"> <div class="Row"> <span style="font: bold 12pt Georgia; color: #000;">Every Kid In Oregon Should Be A Healthy Kid!</span> <p style="font: 10pt Verdana; color: #000;">Depending on family income, children may be eligible for free or low-cost health coverage for doctor visits, dental care, vision, medicines and more through the Clear One Healthy KidsConnect program. Your child must have been without health insurance for two months (though there are exceptions to this rule for special circumstances, like a parent’s job loss or a child’s serious medical need). Child must be under the age of 19.</p> </div> </div> </div> </div> <div style="clear: both;"></div> <div style="float: left; width: 950px; height: 62px; margin-top: 2px; margin-left: 30px; text-align: left;"> <div style="float: left;"> <div class="Row"> <span style="font: bold 10pt Verdana; color: #ececec; margin-bottom: 0px;">Travel Freely</span> </div> <div class="Row"> <span style="font: bold 10pt Verdana; color: #aaa; margin-bottom: 0px;">Holistic Health Insurance</span> </div> <div class="Row"> <span style="font: bold 10pt Verdana; color: #FFF; margin-bottom: 0px;">Every Kid Should Be Healthy!</span> </div> </div> <div style="float: right;"> <div class="Row"> <asp:LinkButton ID="lnkPrevious" runat="server" OnCommand="SwitchPane" CommandArgument="Previous">Previous</asp:LinkButton> <asp:LinkButton ID="lnkStop" runat="server" OnCommand="SwitchPane" CommandArgument="Pause">Pause</asp:LinkButton> <asp:LinkButton ID="lnkPlay" runat="server" OnCommand="SwitchPane" CommandArgument="Play">Play</asp:LinkButton> <asp:LinkButton ID="lnkNext" runat="server" OnCommand="SwitchPane" CommandArgument="Next">Next</asp:LinkButton> </div> </div> </div> </div> </ContentTemplate> <Triggers> <%--<asp:AsyncPostBackTrigger ControlID="tmStartupTimer" EventName="Tick" />--%> <asp:AsyncPostBackTrigger ControlID="tmAjaxTimer" EventName="Tick" /> </Triggers> </asp:UpdatePanel><script type="text/javascript"> var browser = navigator.appName; var SLInstalled = false; if (browser == 'Microsoft Internet Explorer') { try { var slControl = new ActiveXObject('AgControl.AgControl'); //IE SLInstalled = true; } catch (e) { SLInstalled = false; } } else { try { if (navigator.plugins["Silverlight Plug-In"]) // Other Than IE { SLInstalled = true; } } catch (e) { SLInstalled = false; } } document.getElementById('hdSilverlightInstalled').value = SLInstalled; if (SLInstalled == true) { Hide('<%= Head_Image.ClientID %>'); stopTimer(); } else { Hide('<%= Head_Silverlight.ClientID %>'); } function Hide(id) { if (document.getElementById) { obj = document.getElementById(id); if (obj.style.display == "none") { obj.style.display = ""; } else { obj.style.display = "none"; } } } function stopTimer() { var timer = $find('tmAjaxTimer'); //Sys.Debug.trace(timer.get_interval()); timer._stopTimer(); } </script>Thanks!
Matt
EDIT: Of course I find the solution a few minutes after I post this... If anyone else has the same issue I had to make sure I was not calling my stopTimer function until the DOM had been fully loaded. I used the following script at the end of my page to accomplish this:
<script type="text/javascript"> // Detect DOM ready... if ready, call stop timer function function pageLoad() { stopTimer(); } </script>firebirdguy
Member
2 Points
1 Post
Re: ASP.NET 2.0 AJAX Timer Hacks! How to Stop/Start ASP.NET AJAX Timer Clinet Side
Aug 22, 2010 08:50 PM|LINK
[TIMERID].Enabled = true;
[TIMERID].Enabled = false;
miss_just_le...
Member
42 Points
77 Posts
Re: ASP.NET 2.0 AJAX Timer Hacks! How to Stop/Start ASP.NET AJAX Timer Clinet Side
Mar 09, 2011 09:04 AM|LINK
How do I apply this on VB??? Is this Javascript? if this is then i'm doomed as i don't know anything about JS :)
athar_techsa...
Member
554 Points
316 Posts
Re: ASP.NET 2.0 AJAX Timer Hacks! How to Stop/Start ASP.NET AJAX Timer Clinet Side
Sep 28, 2011 08:56 AM|LINK
Hi
How to call these functions on btnStart and btnStop from code behind in c#?
Thanks