Home update panel is updating entire page instead of just grid view
Reply: 1

update panel is updating entire page instead of just grid view

user9068134
1#
user9068134 Published in 2017-12-07 15:37:12Z

I'm trying to use an ajax timer and a update panel to update only my gridview, but it keeps resetting the entire page. What am I doing wrong? Here is my code.

aspx page:

        <div class="row text-center">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <Triggers>
                <asp:PostBackTrigger ControlID="gvShowContent" />
            </Triggers>
            <ContentTemplate>
                <asp:Timer ID="Timer1" runat="server" Interval="60000" OnTick="Timer1_Tick"></asp:Timer>
                <asp:GridView ID="gvShowContent" runat="server" OnRowCommand="gvShowContent_RowCommand" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
                    <AlternatingRowStyle BackColor="White" />
                    <Columns>
                        <asp:BoundField DataField="Course_Code" HeaderText="Course Code" />
                        <asp:BoundField DataField="Content_Name" HeaderText="Title" />
                        <asp:BoundField DataField="Content_Description" HeaderText="Description" />
                        <asp:BoundField DataField="Content_Title" HeaderText="File Name" />
                        <asp:TemplateField HeaderText="Download">
                            <ItemTemplate>
                                <asp:LinkButton ID="lnkDownload" runat="server" CommandArgument='<%# Eval("Content_Title") %>' CommandName="cmd">Download</asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                    <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                    <SortedAscendingCellStyle BackColor="#FDF5AC" />
                    <SortedAscendingHeaderStyle BackColor="#4D0000" />
                    <SortedDescendingCellStyle BackColor="#FCF6C0" />
                    <SortedDescendingHeaderStyle BackColor="#820000" />
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

Codebehind:

protected void Timer1_Tick(object sender, EventArgs e)
    {
        gvShowContent.DataSource = proxy.ShowContent();
        gvShowContent.DataBind();
    }
Asif.Ali
2#
Asif.Ali Reply to 2017-12-08 15:25:02Z

There's no need to <trigger> GridView in UpdatePanel: https://msdn.microsoft.com/en-us/library/cc295400.aspx

So remove this:

<Triggers>
    <asp:PostBackTrigger ControlID="gvShowContent" />
</Triggers>

Now bind and update your UpdatePanel:

protected void Timer1_Tick(object sender, EventArgs e)
{
    gvShowContent.DataBind();
    UpdatePanel1.Update();
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303387 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO