简体   繁体   中英

GridView flickering when placed inside UpdatePanel with Timer (asp.net)

I have placed a GridView inside an UpdatePanel together with a timer. Now the problem is that everytime the timer refreshes the image in the GridView blinks. Anybody knows why? Here is my code:

 <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            </asp:Timer>
            <asp:Timer ID="Timer1" runat="server" Interval="100" OnTick="Timer1_Tick">
            </asp:Timer>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:masterConnectionString3 %>" SelectCommand="[GET DATA FROM SQL SERVER]"></asp:SqlDataSource>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="None" Width="940px">
                <Columns>
                    <asp:BoundField DataField="Column1" HeaderText="Column1" HtmlEncode="False" ReadOnly="True" SortExpression="Column1" />
                    <asp:BoundField DataField="Column2" HeaderText="Column2" ReadOnly="True" SortExpression="Column2" />
                </Columns>
            </asp:GridView>
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
                </ContentTemplate>
            </asp:UpdatePanel>

I fixed it by using local images in the GridView and only updating the GridView when needed using:

UpdateMode="Conditional" in the updatepanel and UpdatePanel.Update(); in the code-behind. Works great now!

Reference and example code can be found at: http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.updatemode.aspx

The GridView blinks because a postback occured by the timer. Place the timer inside a different update panel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM