Pergunta

I have a page that may or may not refresh itself.

And I have a checkbox that will control it, but I have no idea how to implement it.

I've tried to use <asp:Timer> component, but it doesn't work.

Using setInterval / setTimeout from JS, I can't achieve this.

My question is - What .NET component or JS/Jquery attribute I have to use to achieve this?

Foi útil?

Solução

You can use this if you are using jQuery:

$(function(){
    
    $('#timercheck').on('change', function () {
       if ($(':checked').length > 0) {
          clearInterval(timer);
       }
    });

    var timer = setInterval(function(){
       window.location.reload();
    },5000);

});

Here #timercheck is the id of checkbox.

Demo @ Fiddle

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top