locked
stop full page postback on gridveiw sorting RRS feed

  • Question

  • User-153404742 posted

    I've done this on other pages where I have single gridviews but I have a page where I'm creating dynamic gridviews that are under a listview control, which is under under listview control.  Each time I sort a grid, it posts back the full page.  I tried placing gridviews inside update panel to allow partial rendering and it still postsback full page....so basically design is as follows:

     <asp:ListView ID="lvParent" runat="server" OnItemDataBound="lvParent_ItemDataBound" DataKeyNames="ParentName">
                            <ItemTemplate>

    <asp:ListView ID="lvGrids" runat="server" DataKeyNames="GridNumber" OnItemDataBound="lvGrids_ItemDataBound">
     
                                    <ItemTemplate>
                                               <asp:GridView ID="gvChildGrid" runat="server" AllowSorting="true" OnSorting="gvChildGrid_Sorting">
    .....
    so the gvChilGrids will be dynamically created and could be any number of grids.  When OnSorting runs for any of the child grid, the whole page is refreshed but I just need to rebind that specific childgrid with new sorting without full postback.  Placing the gvChildGrid inside <updaePanel> didn't work.
    Thursday, May 6, 2021 6:55 PM

All replies

  • User-1545767719 posted

    For the controls which trigger partial postback using UpdatePanel, try to set their ClientIDMode property to AutoID if you use ASP.NET 4 or later.

    Thursday, May 6, 2021 10:23 PM
  • User-939850651 posted

    Hi inkaln,

    According to your requirements, have you tried setting the EnableSortingAndPagingCallbacks property of the grid view?

    By default, when a sorting or paging operation is performed, the GridView control posts back to the server to perform the operation. When the  EnableSortingAndPagingCallbacks property is set to true, a service is called on the client to perform sorting and paging operations, which eliminates the need to post back to the server.

    Best regards,

    Xudong Peng

    Friday, May 7, 2021 5:29 AM
  • User-153404742 posted

    I think it's an issue with javascript where we have a + - to collapse and expand each gridview.  There are settings that have each grid collapsed or expanded the first time it loads page...but if a user collapses a gridview that is exapnded, it should stay collapsed when another gridview is being sorted....but It's grabbing the original value.  so I have the following inside  <asp:ListView ID="lvGrids">

                                            <div class="box box-default" id="divBlk" runat="server" data-is-collapsed='<%# Eval("IsGridCollapsed") %>'>

    then I have the <asp:Gridview> which populated dynamically....so each gridview has a plus/minus to exapnd and collapse.

    .....the javascript has the following in the 

     <script type="text/javascript">
                    var prm = Sys.WebForms.PageRequestManager.getInstance();
     
                    prm.add_endRequest(function () {
     
                        $('.box[data-is-collapsed="False"]').boxWidget('expand');
                        $('.box[data-is-collapsed="True"]').boxWidget('collapse');
    </script>
    I need the collapsed panels to stay collapsed and expanded to stay expanded but instead, if I collapse grid2 and sort on grid3, grid2 gets expanded again as the original value is true for that grid in <%# Eval("IsGridCollapsed") %>'

    Friday, May 7, 2021 6:07 PM
  • User-939850651 posted

    Hi inkaln,

    I think it's an issue with javascript where we have a + - to collapse and expand each gridview.  There are settings that have each grid collapsed or expanded the first time it loads page...but if a user collapses a gridview that is exapnded, it should stay collapsed when another gridview is being sorted....but It's grabbing the original value.

    The script you described is only used to show or hide the content of the element, and will not generate a postback.

    So I think this has nothing to do with the folding or unfolding of the GridView. When you sort any one of the GridViews, a postback will occur, which will affect the UpdatePanel and cause other GridViews to redisplay.

    I think you have to save the current GridViews' data source state and update it each postback.

    Best regards,

    Xudong Peng

    Monday, May 10, 2021 10:14 AM