How to prevent Postback on GridView paging in UpdatePanel

gridviewpagingupdatepanel

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

Best Answer

I got the solution. I have to put

<xhtmlConformance mode="Transitional"/> 

element in web.Config file.