Search code examples
c#asp.netajaxupdatepanelpostback

ajax update panel control issue


I have an update panel that updates a grid-view , the grid-view is connected to a mySql data-source and the trigger for update panel is a timer that ticks every 1sec.

but the problem is when the timer ticks the whole page will post back. any idea ?

<asp:ScriptManager ID="ScriptManager1" OnLoad="Timer1_Tick" runat="server" />
            <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" ChildrenAsTriggers="true" runat="server">
                <ContentTemplate>
                    <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" Enabled="False">
                    </asp:Timer>
                    <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource3">
                        <Columns>
                            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
                            <asp:BoundField DataField="Sensor1" HeaderText="Sensor1" SortExpression="Sensor1" />
                            <asp:BoundField DataField="Sensor2" HeaderText="Sensor2" SortExpression="Sensor2" />
                            <asp:BoundField DataField="Sensor3" HeaderText="Sensor3" SortExpression="Sensor3" />
                            <asp:BoundField DataField="Sensor4" HeaderText="Sensor4" SortExpression="Sensor4" />
                            <asp:BoundField DataField="Time" HeaderText="Time" SortExpression="Time" />
                        </Columns>
                    </asp:GridView>
                    <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:MyDatabaseConnectionString %>" SelectCommand="SELECT * FROM [Customer]" OnSelecting="SqlDataSource3_Selecting"></asp:SqlDataSource>

                </ContentTemplate>
                <Triggers>
                    <asp:PostBackTrigger ControlID="Timer1" />
                </Triggers>
            </asp:UpdatePanel>

the code behind for the timer is :

 protected void Timer1_Tick(object sender, EventArgs e)
    {
        GridView3.DataBind();
    }

Solution

  • I changed the trigger tag like the code below and it worked :)

                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Timer1" />
                </Triggers>