Blog Home  Home Feed your aggregator (RSS 2.0)  
GridView's EnableSortingAndPagingCallbacks problem - Manuel Abadia's ASP.NET stuff
 
# Monday, February 20, 2006

I was "playing" with the ObjectDataSource's example from Part 2 when I realized I didn't enabled client callbacks for paging and sorting. I set GridView's EnableSortingAndPagingCallbacks to true and tried it. To my surprise, it didn't work! I was confused because I had tried it that in the past and it worked without any problems so it made no sense that it wasn't working now.

Of course the first thing that comes to my head in those situations is: "There's a bug in GridView's implementation". The reality is that 95% of the time it's my own fault but one never finds himself guilty until proven wrong!

I set up an even simpler example to try if it was working and... it worked.

It was time to take a walk and think about it so I went for a walk with my dog. I started thinking about client *callbacks:
* An action triggers the start of a client callback
* The control that will make the client callback packs the information needed and sends it to the page we’re in (using POST)
* The callback is routed to the associated control that unpacks the information, does whatever processing it needs and returns that information to the caller.
* When the control receives the data, it updates the HTML to reflect the changes.

And the problem faced! I was using Response.Write in the Selecting and Selected events to show debug information for the events. I usually didn’t use it as it’s a bad practise but for a quick example comes handy.

If I commented out those Response.Write lines everything worked fine.

This was the response I was receiving before the fix:

HTTP/1.1 200 OK

Server: ASP.NET Development Server/8.0.0.0

Date: Mon, 20 Feb 2006 11:09:40 GMT

X-AspNet-Version: 2.0.50727

Set-Cookie: .DEVINFO=[debug][./]; path=/

Cache-Control: private, no-store

Content-Type: text/html; charset=utf-8

Content-Length: 5056

Connection: Close

 

<br />--- Begin Selecting info ---<br />&nbsp;&nbsp;&nbsp;ExecutingSelectCount = False<br />&nbsp;&nbsp;&nbsp;Arguments.SortExpression = <br />&nbsp;&nbsp;&nbsp;Arguments.StartRowIndex = 18<br />&nbsp;&nbsp;&nbsp;Arguments.MaximumRows = 2<br />&nbsp;&nbsp;&nbsp;Arguments.RetrieveTotalRowCount = True<br />&nbsp;&nbsp;&nbsp;Arguments.TotalRowCount = -1<br />Selecting input parameters<br />You can add parameters to this Dictionary<br />--- End Selecting info ---<br /><br />--- Begin Selected info ---<br />&nbsp;&nbsp;&nbsp;AffectedRows = -1<br />Selected output parameters<br />--- End Selected info ---<br /><br />--- Begin Selecting info ---<br />&nbsp;&nbsp;&nbsp;ExecutingSelectCount = True<br />&nbsp;&nbsp;&nbsp;Arguments.SortExpression = <br />&nbsp;&nbsp;&nbsp;Arguments.StartRowIndex = 18<br />&nbsp;&nbsp;&nbsp;Arguments.MaximumRows = 2<br />&nbsp;&nbsp;&nbsp;Arguments.RetrieveTotalRowCount = True<br />&nbsp;&nbsp;&nbsp;Arguments.TotalRowCount = -1<br />Selecting input parameters<br />You can add parameters to this Dictionary<br />--- End Selecting info ---<br /><br />--- Begin Selected info ---<br />&nbsp;&nbsp;&nbsp;AffectedRows = -1<br />Selected output parameters<br />--- End Selected info ---<br />536|AD3KSK0tPYMVEkzvzFyezn7FUAMtyuD...=|<table cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;">

    <tr>

        <th scope="col">&nbsp;</th><th scope="col"><a onclick="javascript:__gvGridView1.callback(&quot;9|0|2UaF27/PFhEZB2xY7MnIoA==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Sort$Id')">Id</a></th><th scope="col"><a onclick="javascript:__gvGridView1.callback(&quot;9|0|z+TnJLPIB/Uy/EPUkM0BbQ==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Sort$Name')">Name</a></th><th scope="col"><a onclick="javascript:__gvGridView1.callback(&quot;9|0|0kYkbLWMDlm8y+WCizMSjCyJLbYeA421MnxsOJIjOYA=|&quot;); return false;" href="javascript:__doPostBack('GridView1','Sort$Description')">Description</a></th><th scope="col"><a onclick="javascript:__gvGridView1.callback(&quot;9|0|tvd0/n3SD3HWw8hlKx+kHw==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Sort$Price')">Price</a></th>

    </tr><tr>

        <td><a href="javascript:__doPostBack('GridView1','Edit$0')">Edit</a>&nbsp;<a href="javascript:__doPostBack('GridView1','Delete$0')">Delete</a></td><td>33</td><td>prod1</td><td>product1</td><td>1.00</td>

    </tr><tr>

        <td><a href="javascript:__doPostBack('GridView1','Edit$1')">Edit</a>&nbsp;<a href="javascript:__doPostBack('GridView1','Delete$1')">Delete</a></td><td>34</td><td>prod1</td><td>product1</td><td>1.00</td>

    </tr><tr>

        <td colspan="5"><table border="0">

            <tr>

                <td><a onclick="javascript:__gvGridView1.callback(&quot;0|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$1')">1</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;1|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$2')">2</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;2|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$3')">3</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;3|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$4')">4</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;4|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$5')">5</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;5|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$6')">6</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;6|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$7')">7</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;7|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$8')">8</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;8|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$9')">9</a></td><td><span>10</span></td><td><a onclick="javascript:__gvGridView1.callback(&quot;10|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$11')">...</a></td>

            </tr>

        </table></td>

    </tr>

And this one is the one expected:

HTTP/1.1 200 OK

Server: ASP.NET Development Server/8.0.0.0

Date: Mon, 20 Feb 2006 11:03:52 GMT

X-AspNet-Version: 2.0.50727

Set-Cookie: .DEVINFO=[debug][./]; path=/

Cache-Control: private, no-store

Content-Type: text/html; charset=utf-8

Content-Length: 3833

Connection: Close

 

536|AD3KSK0tPYMVEkzvz...=|

<table cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;">

    <tr>

        <th scope="col">&nbsp;</th><th scope="col"><a onclick="javascript:__gvGridView1.callback(&quot;9|0|2UaF27/PFhEZB2xY7MnIoA==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Sort$Id')">Id</a></th><th scope="col"><a onclick="javascript:__gvGridView1.callback(&quot;9|0|z+TnJLPIB/Uy/EPUkM0BbQ==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Sort$Name')">Name</a></th><th scope="col"><a onclick="javascript:__gvGridView1.callback(&quot;9|0|0kYkbLWMDlm8y+WCizMSjCyJLbYeA421MnxsOJIjOYA=|&quot;); return false;" href="javascript:__doPostBack('GridView1','Sort$Description')">Description</a></th><th scope="col"><a onclick="javascript:__gvGridView1.callback(&quot;9|0|tvd0/n3SD3HWw8hlKx+kHw==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Sort$Price')">Price</a></th>

    </tr><tr>

        <td><a href="javascript:__doPostBack('GridView1','Edit$0')">Edit</a>&nbsp;<a href="javascript:__doPostBack('GridView1','Delete$0')">Delete</a></td><td>33</td><td>prod1</td><td>product1</td><td>1.00</td>

    </tr><tr>

        <td><a href="javascript:__doPostBack('GridView1','Edit$1')">Edit</a>&nbsp;<a href="javascript:__doPostBack('GridView1','Delete$1')">Delete</a></td><td>34</td><td>prod1</td><td>product1</td><td>1.00</td>

    </tr><tr>

        <td colspan="5"><table border="0">

            <tr>

                <td><a onclick="javascript:__gvGridView1.callback(&quot;0|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$1')">1</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;1|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$2')">2</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;2|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$3')">3</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;3|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$4')">4</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;4|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$5')">5</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;5|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$6')">6</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;6|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$7')">7</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;7|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$8')">8</a></td><td><a onclick="javascript:__gvGridView1.callback(&quot;8|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$9')">9</a></td><td><span>10</span></td><td><a onclick="javascript:__gvGridView1.callback(&quot;10|0|w7SlFdD5Gv7MDd/o4JIa2A==|&quot;); return false;" href="javascript:__doPostBack('GridView1','Page$11')">...</a></td>

            </tr>

        </table></td>

    </tr>

The only difference was all the lines I wrote using Response.Write after the header.

However, after knowing what was wrong I’d have expected the GridView to complain when it receives a response it can handle properly when doing the client callback.

Monday, February 20, 2006 12:44:43 PM (Romance Standard Time, UTC+01:00)  #    Comments [0]   ASP.NET  | 
Copyright © 2019 Manuel Abadia. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.