how to disable/enable asp.net timer control using Javascript?










3















How to disabled/enabled asp.net timer control using Javascript
My code is: (but not working)



 function timeroff() 

var b = document.getElementById('Timer1');
if (b)
b.disabled = true;


function timeron()
var b = document.getElementById('Timer1');
if (b)
b.disabled = false;











share|improve this question
























  • following link is redirect to somewhere else now :)))

    – Amit Patel
    Dec 23 '11 at 9:33















3















How to disabled/enabled asp.net timer control using Javascript
My code is: (but not working)



 function timeroff() 

var b = document.getElementById('Timer1');
if (b)
b.disabled = true;


function timeron()
var b = document.getElementById('Timer1');
if (b)
b.disabled = false;











share|improve this question
























  • following link is redirect to somewhere else now :)))

    – Amit Patel
    Dec 23 '11 at 9:33













3












3








3








How to disabled/enabled asp.net timer control using Javascript
My code is: (but not working)



 function timeroff() 

var b = document.getElementById('Timer1');
if (b)
b.disabled = true;


function timeron()
var b = document.getElementById('Timer1');
if (b)
b.disabled = false;











share|improve this question
















How to disabled/enabled asp.net timer control using Javascript
My code is: (but not working)



 function timeroff() 

var b = document.getElementById('Timer1');
if (b)
b.disabled = true;


function timeron()
var b = document.getElementById('Timer1');
if (b)
b.disabled = false;








asp.net javascript-events






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 26 '11 at 5:06









Sai Kalyan Kumar Akshinthala

9,86073160




9,86073160










asked Sep 26 '11 at 5:02









Amit PatelAmit Patel

125415




125415












  • following link is redirect to somewhere else now :)))

    – Amit Patel
    Dec 23 '11 at 9:33

















  • following link is redirect to somewhere else now :)))

    – Amit Patel
    Dec 23 '11 at 9:33
















following link is redirect to somewhere else now :)))

– Amit Patel
Dec 23 '11 at 9:33





following link is redirect to somewhere else now :)))

– Amit Patel
Dec 23 '11 at 9:33












2 Answers
2






active

oldest

votes


















0














The following works as long as the timer is not on a Master page because you will get an error stating "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]" when you put this javascript in the header of a Master page.



 function enableTimer() 
var timer = Sys.Application.findComponent(‘<%= Timer1.ClientID %>’);
timer.set_enabled(true);

function disableTimer()
var timer = Sys.Application.findComponent(‘<%= Timer1.ClientID %>’);
timer.set_enabled(false);



see: http://weblogs.asp.net/andrewfrederick/controlling-the-asp-net-timer-control-with-javascript for more details






share|improve this answer

























  • I tried several techniques in an attempt to do this same thing from a Master page but I am not sure how you would do this from a Master page because none of the methods I have tried worked ...

    – David DIlley
    Sep 19 '16 at 19:46


















0














This allows a user to toggle an ASP timer control using ONLY JavaScript.



I'm expanding this, but for now, it's working great ... if I want to disable the timer and not have the update panel refresh while working, it's great, not elegant yet, but it works.



Note, this works with an update panel and a timer named ID=tmrFillAlerts (see below code) ... I'm listing the most basic required ... I took out the CSS and formatting so it would be easier to follow but with all that included, it looks like this ...



The toggles look like this when page loads and you click the user button with timer running ...



enter image description here



Then, after clicking "Turn updates OFF" above, you see this and the timer is stopped ...



enter image description here



You can see the "Turn updates OFF or ON" above are in the code below as ID=lblFlyOutTimerStatus below. Also, the RED ON/OFF ball above is below as ID=lblAlertsTotal.



When the updates are ON ... and you click on the Bell or the Info button, you get a flyout like this thanks to the timer and it is updated every 60 seconds in my case (this shows the bell flyout) enter image description here



The Code Behind C# ...



// Loads the DataList from the TIMER component
private void udpAlertBar(object sender, EventArgs e)
// Do whatever you want here on timer tick ...

// Write the last BELL alert time...
lblAlertTime.Text = "Last update time:<br/>" + DateTime.Now.ToString("MM/dd/yyy hh:mm:ss tt");
// Load the BELL and INFO icon drop down lists
FillBellInfoDataLists();
// Update red alert ballz ....
UpdateAlertBallTotals();



The ASP page code ...



<asp:UpdatePanel id="udpAlertItemUpdater" runat="server">
<ContentTemplate>
<!-- NOTE: The update panel must wrap just this area (UPDpnl kills the javascript for some reason otherwise) -------->
<asp:Label id="lblTimerState" runat="server" Text="on" />
<ul>
<li>
<a href="javascript:void(0)" onclick="toggleUpdateTimer()">
<asp:Label ID="lblFlyOutTimerStatus" runat="server" Text="Turn updates OFF" />
</a>
</li>
</ul>
<asp:Timer ID="tmrFillAlerts" runat="server" OnTick="udpAlertBar" Interval="60000" Enabled="true"/>
</ContentTemplate>
</asp:UpdatePanel>


The JavaScript Code ...



<script type="text/javascript">
function toggleUpdateTimer()
// Gets the timer control on the page named “tmrFillAlerts”
var timerState = $find(“tmrFillAlerts”);
// Gets the label I use for an alert ball on an icon on the page …
var timerStatusRedAlertBall = document.getElementById(‘lblTimerState’);
// Gets the menu item I have on the alert icon that drops down when clicked …
var timerStatusFlyOutLabel = document.getElementById(‘lblFlyOutTimerStatus’);
// Toggle the timer when the menu item is clicked ….
if (timerState.get_enabled() == true)
stopUpdateTimer(); // NOTE: stop the timer, then disable …
timerState.set_enabled(false);
timerStatusRedAlertBall.innerHTML = “OFF”;
timerStatusFlyOutLabel.innerHTML = “Turn Updates ON”;
else
timerState.set_enabled(true); // NOTE: Enable the timer, then start ….
startUpdateTimer();
timerStatusRedAlertBall.innerHTML = “on”;
timerStatusFlyOutLabel.innerHTML = “Turn Updates OFF”;


function stopUpdateTimer()
var timer = $find(“tmrFillAlerts”);
timer._stopTimer();


function startUpdateTimer()
var timer = $find(“tmrFillAlerts”);
timer._startTimer();

</script>


I stripped out everything but the relevant items to get it working ... otherwise this would have been ten pages long!!



Works for me in all browsers at present from an IIS 8.5 running .NET ver: 4.0.30319.42000



It's a work in progress, that was quickly done, but found some cool stuff out there I thought I'd share. Hope it helps!



Good luck!!






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7550812%2fhow-to-disable-enable-asp-net-timer-control-using-javascript%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The following works as long as the timer is not on a Master page because you will get an error stating "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]" when you put this javascript in the header of a Master page.



     function enableTimer() 
    var timer = Sys.Application.findComponent(‘<%= Timer1.ClientID %>’);
    timer.set_enabled(true);

    function disableTimer()
    var timer = Sys.Application.findComponent(‘<%= Timer1.ClientID %>’);
    timer.set_enabled(false);



    see: http://weblogs.asp.net/andrewfrederick/controlling-the-asp-net-timer-control-with-javascript for more details






    share|improve this answer

























    • I tried several techniques in an attempt to do this same thing from a Master page but I am not sure how you would do this from a Master page because none of the methods I have tried worked ...

      – David DIlley
      Sep 19 '16 at 19:46















    0














    The following works as long as the timer is not on a Master page because you will get an error stating "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]" when you put this javascript in the header of a Master page.



     function enableTimer() 
    var timer = Sys.Application.findComponent(‘<%= Timer1.ClientID %>’);
    timer.set_enabled(true);

    function disableTimer()
    var timer = Sys.Application.findComponent(‘<%= Timer1.ClientID %>’);
    timer.set_enabled(false);



    see: http://weblogs.asp.net/andrewfrederick/controlling-the-asp-net-timer-control-with-javascript for more details






    share|improve this answer

























    • I tried several techniques in an attempt to do this same thing from a Master page but I am not sure how you would do this from a Master page because none of the methods I have tried worked ...

      – David DIlley
      Sep 19 '16 at 19:46













    0












    0








    0







    The following works as long as the timer is not on a Master page because you will get an error stating "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]" when you put this javascript in the header of a Master page.



     function enableTimer() 
    var timer = Sys.Application.findComponent(‘<%= Timer1.ClientID %>’);
    timer.set_enabled(true);

    function disableTimer()
    var timer = Sys.Application.findComponent(‘<%= Timer1.ClientID %>’);
    timer.set_enabled(false);



    see: http://weblogs.asp.net/andrewfrederick/controlling-the-asp-net-timer-control-with-javascript for more details






    share|improve this answer















    The following works as long as the timer is not on a Master page because you will get an error stating "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]" when you put this javascript in the header of a Master page.



     function enableTimer() 
    var timer = Sys.Application.findComponent(‘<%= Timer1.ClientID %>’);
    timer.set_enabled(true);

    function disableTimer()
    var timer = Sys.Application.findComponent(‘<%= Timer1.ClientID %>’);
    timer.set_enabled(false);



    see: http://weblogs.asp.net/andrewfrederick/controlling-the-asp-net-timer-control-with-javascript for more details







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 19 '16 at 19:48

























    answered Sep 19 '16 at 19:42









    David DIlleyDavid DIlley

    2310




    2310












    • I tried several techniques in an attempt to do this same thing from a Master page but I am not sure how you would do this from a Master page because none of the methods I have tried worked ...

      – David DIlley
      Sep 19 '16 at 19:46

















    • I tried several techniques in an attempt to do this same thing from a Master page but I am not sure how you would do this from a Master page because none of the methods I have tried worked ...

      – David DIlley
      Sep 19 '16 at 19:46
















    I tried several techniques in an attempt to do this same thing from a Master page but I am not sure how you would do this from a Master page because none of the methods I have tried worked ...

    – David DIlley
    Sep 19 '16 at 19:46





    I tried several techniques in an attempt to do this same thing from a Master page but I am not sure how you would do this from a Master page because none of the methods I have tried worked ...

    – David DIlley
    Sep 19 '16 at 19:46













    0














    This allows a user to toggle an ASP timer control using ONLY JavaScript.



    I'm expanding this, but for now, it's working great ... if I want to disable the timer and not have the update panel refresh while working, it's great, not elegant yet, but it works.



    Note, this works with an update panel and a timer named ID=tmrFillAlerts (see below code) ... I'm listing the most basic required ... I took out the CSS and formatting so it would be easier to follow but with all that included, it looks like this ...



    The toggles look like this when page loads and you click the user button with timer running ...



    enter image description here



    Then, after clicking "Turn updates OFF" above, you see this and the timer is stopped ...



    enter image description here



    You can see the "Turn updates OFF or ON" above are in the code below as ID=lblFlyOutTimerStatus below. Also, the RED ON/OFF ball above is below as ID=lblAlertsTotal.



    When the updates are ON ... and you click on the Bell or the Info button, you get a flyout like this thanks to the timer and it is updated every 60 seconds in my case (this shows the bell flyout) enter image description here



    The Code Behind C# ...



    // Loads the DataList from the TIMER component
    private void udpAlertBar(object sender, EventArgs e)
    // Do whatever you want here on timer tick ...

    // Write the last BELL alert time...
    lblAlertTime.Text = "Last update time:<br/>" + DateTime.Now.ToString("MM/dd/yyy hh:mm:ss tt");
    // Load the BELL and INFO icon drop down lists
    FillBellInfoDataLists();
    // Update red alert ballz ....
    UpdateAlertBallTotals();



    The ASP page code ...



    <asp:UpdatePanel id="udpAlertItemUpdater" runat="server">
    <ContentTemplate>
    <!-- NOTE: The update panel must wrap just this area (UPDpnl kills the javascript for some reason otherwise) -------->
    <asp:Label id="lblTimerState" runat="server" Text="on" />
    <ul>
    <li>
    <a href="javascript:void(0)" onclick="toggleUpdateTimer()">
    <asp:Label ID="lblFlyOutTimerStatus" runat="server" Text="Turn updates OFF" />
    </a>
    </li>
    </ul>
    <asp:Timer ID="tmrFillAlerts" runat="server" OnTick="udpAlertBar" Interval="60000" Enabled="true"/>
    </ContentTemplate>
    </asp:UpdatePanel>


    The JavaScript Code ...



    <script type="text/javascript">
    function toggleUpdateTimer()
    // Gets the timer control on the page named “tmrFillAlerts”
    var timerState = $find(“tmrFillAlerts”);
    // Gets the label I use for an alert ball on an icon on the page …
    var timerStatusRedAlertBall = document.getElementById(‘lblTimerState’);
    // Gets the menu item I have on the alert icon that drops down when clicked …
    var timerStatusFlyOutLabel = document.getElementById(‘lblFlyOutTimerStatus’);
    // Toggle the timer when the menu item is clicked ….
    if (timerState.get_enabled() == true)
    stopUpdateTimer(); // NOTE: stop the timer, then disable …
    timerState.set_enabled(false);
    timerStatusRedAlertBall.innerHTML = “OFF”;
    timerStatusFlyOutLabel.innerHTML = “Turn Updates ON”;
    else
    timerState.set_enabled(true); // NOTE: Enable the timer, then start ….
    startUpdateTimer();
    timerStatusRedAlertBall.innerHTML = “on”;
    timerStatusFlyOutLabel.innerHTML = “Turn Updates OFF”;


    function stopUpdateTimer()
    var timer = $find(“tmrFillAlerts”);
    timer._stopTimer();


    function startUpdateTimer()
    var timer = $find(“tmrFillAlerts”);
    timer._startTimer();

    </script>


    I stripped out everything but the relevant items to get it working ... otherwise this would have been ten pages long!!



    Works for me in all browsers at present from an IIS 8.5 running .NET ver: 4.0.30319.42000



    It's a work in progress, that was quickly done, but found some cool stuff out there I thought I'd share. Hope it helps!



    Good luck!!






    share|improve this answer



























      0














      This allows a user to toggle an ASP timer control using ONLY JavaScript.



      I'm expanding this, but for now, it's working great ... if I want to disable the timer and not have the update panel refresh while working, it's great, not elegant yet, but it works.



      Note, this works with an update panel and a timer named ID=tmrFillAlerts (see below code) ... I'm listing the most basic required ... I took out the CSS and formatting so it would be easier to follow but with all that included, it looks like this ...



      The toggles look like this when page loads and you click the user button with timer running ...



      enter image description here



      Then, after clicking "Turn updates OFF" above, you see this and the timer is stopped ...



      enter image description here



      You can see the "Turn updates OFF or ON" above are in the code below as ID=lblFlyOutTimerStatus below. Also, the RED ON/OFF ball above is below as ID=lblAlertsTotal.



      When the updates are ON ... and you click on the Bell or the Info button, you get a flyout like this thanks to the timer and it is updated every 60 seconds in my case (this shows the bell flyout) enter image description here



      The Code Behind C# ...



      // Loads the DataList from the TIMER component
      private void udpAlertBar(object sender, EventArgs e)
      // Do whatever you want here on timer tick ...

      // Write the last BELL alert time...
      lblAlertTime.Text = "Last update time:<br/>" + DateTime.Now.ToString("MM/dd/yyy hh:mm:ss tt");
      // Load the BELL and INFO icon drop down lists
      FillBellInfoDataLists();
      // Update red alert ballz ....
      UpdateAlertBallTotals();



      The ASP page code ...



      <asp:UpdatePanel id="udpAlertItemUpdater" runat="server">
      <ContentTemplate>
      <!-- NOTE: The update panel must wrap just this area (UPDpnl kills the javascript for some reason otherwise) -------->
      <asp:Label id="lblTimerState" runat="server" Text="on" />
      <ul>
      <li>
      <a href="javascript:void(0)" onclick="toggleUpdateTimer()">
      <asp:Label ID="lblFlyOutTimerStatus" runat="server" Text="Turn updates OFF" />
      </a>
      </li>
      </ul>
      <asp:Timer ID="tmrFillAlerts" runat="server" OnTick="udpAlertBar" Interval="60000" Enabled="true"/>
      </ContentTemplate>
      </asp:UpdatePanel>


      The JavaScript Code ...



      <script type="text/javascript">
      function toggleUpdateTimer()
      // Gets the timer control on the page named “tmrFillAlerts”
      var timerState = $find(“tmrFillAlerts”);
      // Gets the label I use for an alert ball on an icon on the page …
      var timerStatusRedAlertBall = document.getElementById(‘lblTimerState’);
      // Gets the menu item I have on the alert icon that drops down when clicked …
      var timerStatusFlyOutLabel = document.getElementById(‘lblFlyOutTimerStatus’);
      // Toggle the timer when the menu item is clicked ….
      if (timerState.get_enabled() == true)
      stopUpdateTimer(); // NOTE: stop the timer, then disable …
      timerState.set_enabled(false);
      timerStatusRedAlertBall.innerHTML = “OFF”;
      timerStatusFlyOutLabel.innerHTML = “Turn Updates ON”;
      else
      timerState.set_enabled(true); // NOTE: Enable the timer, then start ….
      startUpdateTimer();
      timerStatusRedAlertBall.innerHTML = “on”;
      timerStatusFlyOutLabel.innerHTML = “Turn Updates OFF”;


      function stopUpdateTimer()
      var timer = $find(“tmrFillAlerts”);
      timer._stopTimer();


      function startUpdateTimer()
      var timer = $find(“tmrFillAlerts”);
      timer._startTimer();

      </script>


      I stripped out everything but the relevant items to get it working ... otherwise this would have been ten pages long!!



      Works for me in all browsers at present from an IIS 8.5 running .NET ver: 4.0.30319.42000



      It's a work in progress, that was quickly done, but found some cool stuff out there I thought I'd share. Hope it helps!



      Good luck!!






      share|improve this answer

























        0












        0








        0







        This allows a user to toggle an ASP timer control using ONLY JavaScript.



        I'm expanding this, but for now, it's working great ... if I want to disable the timer and not have the update panel refresh while working, it's great, not elegant yet, but it works.



        Note, this works with an update panel and a timer named ID=tmrFillAlerts (see below code) ... I'm listing the most basic required ... I took out the CSS and formatting so it would be easier to follow but with all that included, it looks like this ...



        The toggles look like this when page loads and you click the user button with timer running ...



        enter image description here



        Then, after clicking "Turn updates OFF" above, you see this and the timer is stopped ...



        enter image description here



        You can see the "Turn updates OFF or ON" above are in the code below as ID=lblFlyOutTimerStatus below. Also, the RED ON/OFF ball above is below as ID=lblAlertsTotal.



        When the updates are ON ... and you click on the Bell or the Info button, you get a flyout like this thanks to the timer and it is updated every 60 seconds in my case (this shows the bell flyout) enter image description here



        The Code Behind C# ...



        // Loads the DataList from the TIMER component
        private void udpAlertBar(object sender, EventArgs e)
        // Do whatever you want here on timer tick ...

        // Write the last BELL alert time...
        lblAlertTime.Text = "Last update time:<br/>" + DateTime.Now.ToString("MM/dd/yyy hh:mm:ss tt");
        // Load the BELL and INFO icon drop down lists
        FillBellInfoDataLists();
        // Update red alert ballz ....
        UpdateAlertBallTotals();



        The ASP page code ...



        <asp:UpdatePanel id="udpAlertItemUpdater" runat="server">
        <ContentTemplate>
        <!-- NOTE: The update panel must wrap just this area (UPDpnl kills the javascript for some reason otherwise) -------->
        <asp:Label id="lblTimerState" runat="server" Text="on" />
        <ul>
        <li>
        <a href="javascript:void(0)" onclick="toggleUpdateTimer()">
        <asp:Label ID="lblFlyOutTimerStatus" runat="server" Text="Turn updates OFF" />
        </a>
        </li>
        </ul>
        <asp:Timer ID="tmrFillAlerts" runat="server" OnTick="udpAlertBar" Interval="60000" Enabled="true"/>
        </ContentTemplate>
        </asp:UpdatePanel>


        The JavaScript Code ...



        <script type="text/javascript">
        function toggleUpdateTimer()
        // Gets the timer control on the page named “tmrFillAlerts”
        var timerState = $find(“tmrFillAlerts”);
        // Gets the label I use for an alert ball on an icon on the page …
        var timerStatusRedAlertBall = document.getElementById(‘lblTimerState’);
        // Gets the menu item I have on the alert icon that drops down when clicked …
        var timerStatusFlyOutLabel = document.getElementById(‘lblFlyOutTimerStatus’);
        // Toggle the timer when the menu item is clicked ….
        if (timerState.get_enabled() == true)
        stopUpdateTimer(); // NOTE: stop the timer, then disable …
        timerState.set_enabled(false);
        timerStatusRedAlertBall.innerHTML = “OFF”;
        timerStatusFlyOutLabel.innerHTML = “Turn Updates ON”;
        else
        timerState.set_enabled(true); // NOTE: Enable the timer, then start ….
        startUpdateTimer();
        timerStatusRedAlertBall.innerHTML = “on”;
        timerStatusFlyOutLabel.innerHTML = “Turn Updates OFF”;


        function stopUpdateTimer()
        var timer = $find(“tmrFillAlerts”);
        timer._stopTimer();


        function startUpdateTimer()
        var timer = $find(“tmrFillAlerts”);
        timer._startTimer();

        </script>


        I stripped out everything but the relevant items to get it working ... otherwise this would have been ten pages long!!



        Works for me in all browsers at present from an IIS 8.5 running .NET ver: 4.0.30319.42000



        It's a work in progress, that was quickly done, but found some cool stuff out there I thought I'd share. Hope it helps!



        Good luck!!






        share|improve this answer













        This allows a user to toggle an ASP timer control using ONLY JavaScript.



        I'm expanding this, but for now, it's working great ... if I want to disable the timer and not have the update panel refresh while working, it's great, not elegant yet, but it works.



        Note, this works with an update panel and a timer named ID=tmrFillAlerts (see below code) ... I'm listing the most basic required ... I took out the CSS and formatting so it would be easier to follow but with all that included, it looks like this ...



        The toggles look like this when page loads and you click the user button with timer running ...



        enter image description here



        Then, after clicking "Turn updates OFF" above, you see this and the timer is stopped ...



        enter image description here



        You can see the "Turn updates OFF or ON" above are in the code below as ID=lblFlyOutTimerStatus below. Also, the RED ON/OFF ball above is below as ID=lblAlertsTotal.



        When the updates are ON ... and you click on the Bell or the Info button, you get a flyout like this thanks to the timer and it is updated every 60 seconds in my case (this shows the bell flyout) enter image description here



        The Code Behind C# ...



        // Loads the DataList from the TIMER component
        private void udpAlertBar(object sender, EventArgs e)
        // Do whatever you want here on timer tick ...

        // Write the last BELL alert time...
        lblAlertTime.Text = "Last update time:<br/>" + DateTime.Now.ToString("MM/dd/yyy hh:mm:ss tt");
        // Load the BELL and INFO icon drop down lists
        FillBellInfoDataLists();
        // Update red alert ballz ....
        UpdateAlertBallTotals();



        The ASP page code ...



        <asp:UpdatePanel id="udpAlertItemUpdater" runat="server">
        <ContentTemplate>
        <!-- NOTE: The update panel must wrap just this area (UPDpnl kills the javascript for some reason otherwise) -------->
        <asp:Label id="lblTimerState" runat="server" Text="on" />
        <ul>
        <li>
        <a href="javascript:void(0)" onclick="toggleUpdateTimer()">
        <asp:Label ID="lblFlyOutTimerStatus" runat="server" Text="Turn updates OFF" />
        </a>
        </li>
        </ul>
        <asp:Timer ID="tmrFillAlerts" runat="server" OnTick="udpAlertBar" Interval="60000" Enabled="true"/>
        </ContentTemplate>
        </asp:UpdatePanel>


        The JavaScript Code ...



        <script type="text/javascript">
        function toggleUpdateTimer()
        // Gets the timer control on the page named “tmrFillAlerts”
        var timerState = $find(“tmrFillAlerts”);
        // Gets the label I use for an alert ball on an icon on the page …
        var timerStatusRedAlertBall = document.getElementById(‘lblTimerState’);
        // Gets the menu item I have on the alert icon that drops down when clicked …
        var timerStatusFlyOutLabel = document.getElementById(‘lblFlyOutTimerStatus’);
        // Toggle the timer when the menu item is clicked ….
        if (timerState.get_enabled() == true)
        stopUpdateTimer(); // NOTE: stop the timer, then disable …
        timerState.set_enabled(false);
        timerStatusRedAlertBall.innerHTML = “OFF”;
        timerStatusFlyOutLabel.innerHTML = “Turn Updates ON”;
        else
        timerState.set_enabled(true); // NOTE: Enable the timer, then start ….
        startUpdateTimer();
        timerStatusRedAlertBall.innerHTML = “on”;
        timerStatusFlyOutLabel.innerHTML = “Turn Updates OFF”;


        function stopUpdateTimer()
        var timer = $find(“tmrFillAlerts”);
        timer._stopTimer();


        function startUpdateTimer()
        var timer = $find(“tmrFillAlerts”);
        timer._startTimer();

        </script>


        I stripped out everything but the relevant items to get it working ... otherwise this would have been ten pages long!!



        Works for me in all browsers at present from an IIS 8.5 running .NET ver: 4.0.30319.42000



        It's a work in progress, that was quickly done, but found some cool stuff out there I thought I'd share. Hope it helps!



        Good luck!!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 6:00









        Mike HawkMike Hawk

        162




        162



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7550812%2fhow-to-disable-enable-asp-net-timer-control-using-javascript%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            What does pagestruct do in Eviews?

            Dutch intervention in Lombok and Karangasem

            Channel Islands