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.
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 using a master page. :(
Thank you for taking the time to do that. So, I just re-learned an important lesson.
Remember the test page I set up to test the issue where I took only the related code so there would be "no interference" from anything else on the page. Well, I had some code in that page from a previous test. I went back and removed EVERYTHING except the
bare minimum needed for this test and everything worked just as it did for you. LESSON LEARNED (AGAIN): When you test, don't assume anything and test in as much of a pristine environment as you can.
But the question remains, what is causing my code NOT to work? In my test page, I found that I had code in the Page_Load that was executing a "Response.Write" from a previous test. The "Response.Write" breaks the gridview paging in the UpdatePanel. I have
toggled that line off and on to verify it is the culprit.
I went back to my original page, but I don't have anything like that. So far, I cannot find what is causing the issue there, but I know that something is causing it, so I can methodically work at this.
Can anyone explain what the Response.Write is doing to the page to break this?
I wasn't using the response.write during an async postback. I executed during page_load. At that point the async postbacks in mygridview wouldn't work. Removing the Response.Write got things working in my test page, but I don't have any code like this in
production. I'm also still curious why this happens.
Also, I wasn't looking for a postback trigger. Making the gridview a postback trigger for itself seems like it would defeat the purpose of putting it in an updatepanel in the first place. The gridview should page and sort asynchronously, but it isn't. Something
in my page is getting in the way. Luckily, I finally tracked it down.
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?
Member
2 Points
45 Posts
Gridview inside UpdatePanel, paging/sorting doesn't work ONLY when using MasterPage
Dec 22, 2013 02:29 PM|mattdaddym2|LINK
Hi all,
Gridview looks a bit like this:
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:
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 using a master page. :(
Thanks all!
Participant
1390 Points
323 Posts
Re: Gridview inside UpdatePanel, paging/sorting doesn't work ONLY when using MasterPage
Dec 23, 2013 04:20 AM|valuja|LINK
Hi,
I have created a test site to try to see the problem that you have. Tha master page looks like this:
and the content page with code:
This works without any problems so I wonder what the main differences are from your code so that I may see if I can find the error?
Best regards
Johan
Member
2 Points
45 Posts
Re: Gridview inside UpdatePanel, paging/sorting doesn't work ONLY when using MasterPage
Dec 23, 2013 12:50 PM|mattdaddym2|LINK
Thank you for taking the time to do that. So, I just re-learned an important lesson.
Remember the test page I set up to test the issue where I took only the related code so there would be "no interference" from anything else on the page. Well, I had some code in that page from a previous test. I went back and removed EVERYTHING except the bare minimum needed for this test and everything worked just as it did for you. LESSON LEARNED (AGAIN): When you test, don't assume anything and test in as much of a pristine environment as you can.
But the question remains, what is causing my code NOT to work? In my test page, I found that I had code in the Page_Load that was executing a "Response.Write" from a previous test. The "Response.Write" breaks the gridview paging in the UpdatePanel. I have toggled that line off and on to verify it is the culprit.
I went back to my original page, but I don't have anything like that. So far, I cannot find what is causing the issue there, but I know that something is causing it, so I can methodically work at this.
Can anyone explain what the Response.Write is doing to the page to break this?
Thanks!
All-Star
30411 Points
3628 Posts
Re: Gridview inside UpdatePanel, paging/sorting doesn't work ONLY when using MasterPage
Dec 24, 2013 02:20 AM|Fuxiang Zhang - MSFT|LINK
Hi mattdaddym2,
Thank you post the issue to asp.net forum.
According to your description, I see that you were using the Response.Write when the updatepanel async post back.
As we all know that we can't use Response.Write during an asynchronous postback. If you want to use it when gridview paging or sorting.
I think you should set it as PostBackTrigger of updatepanel. Like below:
Code behind:
Besides, you can also set it in the code behind like below.
Thanks.
Best Regards!
Member
2 Points
45 Posts
Re: Gridview inside UpdatePanel, paging/sorting doesn't work ONLY when using MasterPage
Dec 24, 2013 04:27 PM|mattdaddym2|LINK
Hi,
I wasn't using the response.write during an async postback. I executed during page_load. At that point the async postbacks in mygridview wouldn't work. Removing the Response.Write got things working in my test page, but I don't have any code like this in production. I'm also still curious why this happens.
Also, I wasn't looking for a postback trigger. Making the gridview a postback trigger for itself seems like it would defeat the purpose of putting it in an updatepanel in the first place. The gridview should page and sort asynchronously, but it isn't. Something in my page is getting in the way. Luckily, I finally tracked it down.
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.
All-Star
30411 Points
3628 Posts
Re: Gridview inside UpdatePanel, paging/sorting doesn't work ONLY when using MasterPage
Dec 24, 2013 08:10 PM|Fuxiang Zhang - MSFT|LINK
Hi mattdaddym,
I'm glad to see you post back.
According to your description, I'm sorry to say I cannot reproduce the scenes you described.
Would you mind share a simple demo with us and let us reproduce the scenes.
Then we will provide further solutions for you. Thanks.
Best Regards!