Question

Another gridview in updatepanel paging/sorting questions folks.

Gridview looks like this:

<asp:UpdatePanel runat="server"
ID="upGdvPendingReview"
ChildrenAsTriggers="true"
UpdateMode="Conditional">
  <ContentTemplate>
     <asp:GridView
          ID="gdvPendingReview"
          runat="server"                                                            
          PageSize="10"
          AllowPaging="true"
          AllowSorting="true"
          >
           <columnCrudHere>                                             
     </asp:GridView>
   </ContentTemplate>
</asp:UpdatePanel>

Gridview is bound to linqdatasource using the Selecting event. This code works perfectly without the updatepanel. It also works perfectly if I copy to a page that isn't a Content Page to a Master Page. I've read a lot of posts about gridview issues in update panels with paging and sorting. In fact, there is one where they guy comments at the end that he got it working but it still fails when using a MasterPage. I've tried using a scriptmanager in the same page as the gridview and changing various options of the scriptmanager. To get it working, I just create a new page, copy my gridview, linqdatasource, scriptmanager, and code behind...and boom it works. It makes me wonder if I have something else in the page getting in the way. I do have other updatepanels where I can update content fine. So, this...combined with the post where the same issue is mentioned briefly has me perplexed.

I've also tried explicitly listing the event:

<Triggers>
  <asp:AsyncPostBackTrigger ControlID="gdvPendingReview" EventName="PageIndexChanging" />
</Triggers>

Here is the post where it seems like someone is having the same issue (at the very end): GridView PAGING inside UpdatePanel does not work for second page change, why?

***Update

As I continue to test this, it becomes more frustrating and fascinating. I have created two new pages with only the gridview, linqdatasource, scriptmanager, and databinding methods. One page has no master....the other page has a master (but a completely new and clean one to avoid any possible interference). Same results! Paging/Sorting works great asynchronously as long as I'm not referring to a master page. :(

***Update

I should admit that I am a liar. The test page I set up (with Master) did have some code left over from a previous test. In fact, when I comment this code out, my GridView paging works inside the UpdatePanel when using a MasterPage. The culprit? A "Response.Write". When I toggle this off an on I can create the issue on demand. Big lesson "Relearned" here about testing and not assuming anything. There is still some mystery, though.

Interestingly, I don't have a Response.Write or anything I can find in my code for the original page with the issue. Does anyone have a thought on why the "Response.Write" would break the gridview sorting/paging in the updatepanel? If so, that may help pinpoint what is happening.

Thanks all!

Was it helpful?

Solution

Well, the answer to this issue is a bit embarrassing.

Lesson 1 - When you test, you isolate your issue as completely as possible and do not assume anything.

Lesson 2 - When troubleshooting AJAX issues, look for javascript errors.

Turns out my code works fine. The issue was other updatepanels on the page set to update "always". I noticed a javascript error in Firebug alerting me that an updatepanel couldn't be found when trying to sort/page the gridview I was having issues with. When I try to page my gridview, any updatepanel set to always also tries to update. Well, there is a "hidden" section of my page (visibility is off) with updatepanels. When attempting to sort/page my gridview, javascript is looking for these, I assume to update them, but cannot find them. There is a javascript error and all progress stops. The solution was to change the updatepanels that are hidden all to conditional (which has other repercussions but its bearable).

Does this seem like the correct behavior by default. If an updatepanel is inside another control whose visibility is turned off, should it be attempting to update?

Thanks all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top