How to prevent Postback on GridView paging in UpdatePanel

元气小坏坏 提交于 2019-12-19 11:25:19

问题


I have apply paging in GridView which is in UpdatePanel.When I move forward to the next result set full Postback occur on my Page.Do i need to do some modification in web.config file or in my code.

 [ ASPX ]
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
    <asp:GridView ID="gvCommentSample" runat="server" 
OnPageIndexChanging="gvCommentSample_PageIndexChanging" AllowPaging="true" PageSize="2"
ShowFooter="false" Width="100%" ShowHeader="false" BorderWidth="0px" >
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>

[ CODE BEHIND ]
Dim table As DataTable

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 If Not IsPostBack Then
    bindGridView()
 End If
End Sub
    Private Function GetTable() As DataTable
        table = New DataTable()
        table.Columns.Add("FirstName")
        table.Columns.Add("LastName")

        Dim row As DataRow = table.NewRow()
        row("FirstName") = "John"
        row("LastName") = "Johnoson"
        table.Rows.Add(row)

        row = table.NewRow()
        row("FirstName") = "Johnny"
        row("LastName") = "Marley"
        table.Rows.Add(row)

        row = table.NewRow()
        row("FirstName") = "Kate"
        row("LastName") = "Li"
        table.Rows.Add(row)

        Return table
    End Function
    Public Sub bindGridView()
        gvCommentSample.DataSource = GetTable()
        gvCommentSample.DataBind()
    End Sub
    Protected Sub gvCommentSample_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
        Dim gvCommentSample As GridView = DirectCast(sender, GridView)
        gvCommentSample.PageIndex = e.NewPageIndex
        gvCommentSample.DataSource = GetTable()
        gvCommentSample.DataBind()
    End Sub

回答1:


I got the solution. I have to put

<xhtmlConformance mode="Transitional"/> 

element in web.Config file.




回答2:


this entry we have to do under syste.web, but it didnt work ou for me. i m using the grid in MOSS. after this entry full post back was done again




回答3:


I have a similar issue. Its solved by using The real problem is I have used tdXXXXX = de('_ctl0_CPB_XXXXX');

where de is a function function de(clID)

        {
            return document.getElementById(clID);  
        }       

Previously the control was rendered correctly as _ctl0_CPB_XXXXX, now it has appeneded an extra 0 ie. _ctl00_CPB_XXXXX. This is used throught the application, and its causing the javaScripts failures. Any solutions.



来源:https://stackoverflow.com/questions/4469416/how-to-prevent-postback-on-gridview-paging-in-updatepanel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!