Refresh updatepanel after fixed interval

This is my script:

 <script type="text/javascript">
    function (){

        setTimeout('myFun()', 10000);

    function myFun() {
        var btn = document.getElementById('<%=myBtn.ClientID %>');

My markup:

  • Setting textarea to display:none loses the value when trying to save
  • Client side modal dialog in from the server side code. (how do I do this)
  • Toast notifications in ASP.NET MVC
  • javascript countdown timer for session timeout
  • Difference between two times that are saved as strings using javascript
  • RegisterOnSubmitStatement after client-side validation
  • <asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional">
            <asp:Label ID="lblValue" runat="server" Text=""></asp:Label>
            <asp:AsyncPostBackTrigger ControlID="myBtn" EventName="Click" />
    <asp:Button ID="myBtn" runat="server" Text="hit" />

    Code Behind:

    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            lblValue.Text = "0";
            lblValue.Text = Convert.ToString(Convert.ToInt32(lblValue.Text) + 1);

    I need to refresh the updatepanel after every 10 seconds. But after page load, only once I’m able to achieve that. Is there anything I’m missing? Thanks.

  • Regular expression validator is not allowing non-english characters for \w
  • javascript ASP.NET hiddenfield get value from code behind
  • Design client side for updating multiple partial views with ajax
  • how to render the relative path with tilde into ../../ of relative path in jquery/javascript?
  • Multiple user controls and javascript
  • “Message”:"Invalid web service call, missing value for parameter: \u0027haha\u0027
  • 5 Solutions collect form web for “Refresh updatepanel after fixed interval”

    why don’t you use the AJAX Timer control instead. It’ll serve the same purpose in a neat, concise & efficient manner.

    Both setTimeout() & setInterval() work the same way.

    The key difference is that:

    • setTimeout will wait the specified period of time, run the code we give it, and then stop.
    • setInterval, on the other hand, will wait, run the code—then wait again and run the code again—repeating forever (or until we tell it to stop).

    In brief, setTimeout() runs the supplied code only once after the specified interval, whereas setInterval() runs the code again & again after the specified interval.

    So use:

    <script type="text/javascript">     
         function ()
                 setInterval('myFun()', 10000);      
         function myFun() 
                 var btn = document.getElementById('<%=myBtn.ClientID %>');         

    Source: jQuery – Novice to Ninja

    remove if (!IsPostBack),because of this ,it updated only once,

    IsPostBack means that the page was post back to itself

    !IsPostBack means the first time you load the page of just refresh the page, it was not post from itself

    Why don’t you try AJAX timer control? It is a simple way to postback in some fixed interval.



    insted of click

     var btn = document.getElementById('<%=myBtn.ClientID %>');