RadAjax for ASP.NET

AJAX Timer Send comments on this topic.
See Also
AJAX Timer > AJAX Timer

Glossary Item Box

RadAjaxTimer is a postback timer control. It "ticks" and makes one or more postbacks at a predefined interval.

In order to make this control perform AJAX requests instead of postbacks, put it in AJAX Panel or set it with AJAX Manager.

 

RadAjaxTimer in RadAjaxManager

RadAjaxTimer in RadAjaxPanel



Once you place the control in a WebForm (drag it from VisualStudio toolbox), you can set the server-side AutoStart property of RadAjaxTimer  to true. The control will start ticking on page load. The interval between two ticks can be set with the Interval property. This property accepts values in milliseconds. It's runtime change restarts the timer automatically so that the new value is applied.

RadAjaxTimer fires a Tick event on each tick. You can handle this event in order to perform your own actions when some predefined interval (e.g. five ticks)  has passed.

<rad:RadAjaxTimer AutoStart="true" id="RadAjaxTimer1" runat="server" Interval="3000"></rad:RadAjaxTimer>

You can start/stop the timer control at runtime. In this case the AutoStart property should be set to false (otherwise the control will start on its own). There are two methods for controlling the Timer: Start and Stop:

  • Start method starts the control by setting its IsStarted property to true.
  • Stop method stops the control by setting IsStarted to false.

 

RadAjaxTimer client-side

RadAjaxTimer provides two client-side methods:

  • Start() - starts the Timer
  • Stop() - stops the Timer

The following code exemplifies the usage of these methods:

JavaScript Copy Code
<input type="button" id="StartButton" class="button" onclick="StartTimer();" value="Start"></input>
<input type="button" id="StopButton" class="button" onclick="StopTimer();" value="Stop"></input>
<script type="text/javascript">
   <!--
    document.getElementById( "StartButton").disabled = true;
    function StartTimer()
    {
     <%= RadAjaxTimer1.ClientID %>.Start();
     document.getElementById( "StartButton").disabled = true;
     document.getElementById( "StopButton").disabled = false;
    }

    function StopTimer()
    {
     <%= RadAjaxTimer1.ClientID %>.Stop();
     document.getElementById( "StartButton").disabled = false;
     document.getElementById( "StopButton").disabled = true;
    }
   //-->
</script>
RadAjaxTimer also exposes the OnClientTick event, which will can be cancel if needed:
JavaScript Copy Code
<script type="text/javascript">
            function ClientTick(sender, eventArgs)
            {
               eventArgs.CancelServerTick = true;
               //return false will do the same for you;
            }
        </script>

<rad:RadAjaxTimer id="RadAjaxTimer2" runat="server" AutoStart="true" Interval="1000" OnClientTick="ClientTick">
 

See Also