We have a webgrid that pages and sorts using Xml LoadOnDemand. The paging and sorting works fine. We also have a templated column on the grid that shows an asp button that posts back to the server and processes some things based on the row that that button was in, using the CommandArgument. This also usually works fine, and we had no problem at all with it until we recently added the paging and sorting.
The problem is this:
We search for some data that returns 2 pages. We page to the second page. Everything is fine. We then sort on a different column. Again, everything is fine, and it goes back to the first page. If I then click the button in one of the rows, it seems to think it is on the second page. If I debug it, in InitializeDataSource, the pageindex is 1, which is fine. It binds the grid, does initializelayout, and then it gets weird. Somewhere it seems that the grid is being re-bound, and the page index changes. It calls InitializeLayout 2 more times. Then when it finally gets to my event handler, the pageindex is 2.
I don't know what is causing this to change pages. I suspect it might have something to with the button doing a full postback, whereas the paging and sorting do http requests, but I'm really just guessing that.
We have a workaround where we use Html buttons instead and manually do the postback in javascript, setting the arguments based on the row data, and that seems to work. But it still concerns me that I don't know what is happening here.
Help, anyone?