Click here to Skip to main content
15,887,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a grid that I want to bind every X seconds, but the timer is not waiting until the process is done, it's just executing itself over and over, I even tried creating a variable, and use it as a flag, but it doesn't seem to be working, here is my code(the problem is not in my code behind, if there's any problem it has to be here, because the only thing i do is bind the grid in the tick event):

ASP.NET
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Talk1Rep._Default" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
      <asp:ScriptManager runat="server" ID="ScriptManager1">
        <Scripts>
            <%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=272931&clcid=0x409 --%>
            <%--Framework Scripts--%>
            
            <asp:ScriptReference Name="MsAjaxBundle" />
            <asp:ScriptReference Name="jquery" />
            <asp:ScriptReference Name="jquery.ui.combined" />
            <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
            <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
            <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
            <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
            <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
            <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
            <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
            <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
            <asp:ScriptReference Name="WebFormsBundle" />
            <%--Site Scripts--%>

        </Scripts>
    </asp:ScriptManager>
    <section class="featured">
      <div>
        <table style="width:100%;">
            <tr>
                    
                 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"  ViewStateMode="Enabled">
                   
                   <Triggers>
                              <asp:AsyncPostBackTrigger  ControlID="Timer1" EventName="Tick" />
                        </Triggers>
                        <ContentTemplate>
                            
                            <asp:GridView ID="gv_stats" runat="server" AutoGenerateColumns="False" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" ForeColor="Black" ShowHeaderWhenEmpty="True" Width="100%" OnRowDataBound="gv_stats_RowDataBound" ShowFooter="True" EnableViewState="False" CellSpacing="2" > my gridview
                            </asp:GridView>
                            <hr />
                            <asp:Label ID="Label1" runat="server" Text="Last Update: "></asp:Label>
                            <asp:Label ID="lbl_lastUpdate" runat="server"></asp:Label>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                   <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" EnableViewState="True">
                    </asp:Timer>
                </td>
            </tr>
        </table>
        </div>
    </section>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    </asp:Content>
<asp:Content ID="Content1" runat="server" contentplaceholderid="HeadContent">

</asp:Content>
Posted
Updated 23-Mar-14 18:43pm
v2
Comments
CoderPanda 24-Mar-14 0:47am    
Not sure, but can you try increasing the interval to say 10000?

1 solution

Can you check a flag in your Timer1_Tick()
-> If true GetLatestDataForGrid()
-> Else ignore
-> Set flag=False

And set that flag to TRUE after completion of your gridLoad.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900