Gridview inside UpdatePanel, paging/sorting doesn't work ONLY when using MasterPage - asp.net

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!

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.

Related

User control retains focus incorrectly after TextChanged postback when UC is contained within a detailsview control

I reference a previous post: Focus lost on partial postback with UserControls inside UpdatePanel
where an excellent solution works perfectly for web-page controls within a form.
However, I have placed my UC inside a detailsview template-field (for Edit+Insert).
The UC contains an UpdatePanel needed to adjust the text-formatting and control's style(s) following the TextChanged event of the UC-textbox (AutoPostback=True) during the Edit-mode and Insert-modes of the DetailsView.
As such, when the DetailsView-control is in Edit-mode, and user changes Text in the UC, the textchanged event is fired and the user-entered value is validated and when OK, the thousounds-separator (comma) are added to the UC-textbox-text, BUT, the focus moves to the next field in the DetailsView and QUICKLY returns back to the UC-control.
This incorrect focus-move(s) does NOT occur when the UC is wrapped in updatepanels as noted in the referenced post since the focus and tabbing order works perfectly outside of the DetailsView control.
Here is the aspx markup for the template-field-EDIT (only).
<asp:TemplateField HeaderText="Initial Mileage" SortExpression="IMilage">
<EditItemTemplate>
<asp:UpdatePanel ID="updpnlIMilage" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<TGANumeric:GANumeric ID="ucnumIMileage" runat="server"
Caption="Initial Mileage" HideCaption="True" Width="160"
DisplayMask="999,999" InputMask="999999"
Enabled="True" IsRequired="False"
MinNumber="0" MaxNumber="999999"
Text='<%# Bind("IMilage") %>'
TabIndex="0"
/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ucnumIMileage" />
</Triggers>
</asp:UpdatePanel>
</EditItemTemplate>
Thanks in advance. Your comments are welcome.
Thanks...J.
So are you saying your control hierearchy (partial) is:
UpdatePanel > TGANumeric:GANumeric > UpdatePanel > TextBox
This is an awful lot of overhead to just format a number with a comma, which is the only reason I see for your posting back. As far as I can tell there is nothing you need from the server, so why post?
Or is there?
My thoughts, lose the update panels, disable the AutoPostback on the Textbox, handle the formatting client side if it must be seen immediately, or leave the formatting to the DetailsView field DataStringFormat when it posts after save.
I'm betting this will clear up any focus issues.
Based on all the comments in this thread, I want to explain the actual root cause of the tabbing misbehavior.
1) There were no coding issues or event-issues with the user-control.
2) There were no coding issues or event-issues with the layering of Master-page, Content-page, Ajax update-panels / nested update-panels, details-view and template-fields containing the user-control.
3) The real culprit was a small snippet of code where the page adjusts the web-controls on the form based on the "state" (status) of the page/form. I manage the adjusting of visible and/or enabling of web-controls in a single subroutine in the code-behind so that all of this enabling/disabling visible/not-visible occurs in one place under a set of CASE-statements.
The actual erroneous snippet of code inside the 'sbSetFormState()'-method was messing with the class-variable 'm_eFormState' that actually caused the update panel to re-fire and thus the tabbing got thrown out of sequence.
This was discovered by the great suggestion from 'fnostro' to remove or add functionality features until the mis-behavior exposes itself.
I mark this topic as resolved/closed.
Again, thanks to fnostro !!!

ASP.NET webform Fileupload inside an ascx which is inside an updatepanel in the aspx

here is some code in my page :
<asp:UpdatePanel ID="UpdatePanelEQSelector" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc12:EQSelector ID="custEQSelector" OnEqChange="custEQSelector_OnEqChange" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Inside my user Control, I'm asked to add a fileuploader.
After coding it simply, I tested and my fileuploader is always empty.
I've searched a while and discovered that it was a normal behavior.
The solution to make it work is to add a PostBackTrigger for the updatePanel.
When I tested it in my aspx page, I achieved to do it and my fileUploader had the file.
Then I tried to add it dynamically (to finally do it in my control), it worked with that :
PostBackTrigger trigger = new PostBackTrigger();
trigger.ControlID = this.btnTest.ID;
this._UpdatePanelEQSelector.Triggers.Add(trigger);
But I can't manage to make this code work in my control (I passed my updatePanel as a parameter to my control set in Load, the fileUpload is always empty)
Do you see a solution ?
Thanks
Does it postback, but leaves the control empty? or is it not posting back at all. If it's not posting back at all I'd add this
ScriptManager.GetCurrent(this).RegisterPostBackControl(btnTest);
to the page_load of the user control.
If it is posting back, but the control is empty, then I'd wager there is probably some dodgy html somewhere on the page and the values are getting lost.

Script control is not a registered script control

I have a page that uses CustomerDetails.ascx. It uses CM.ascx. Inside CM.ascx I use AJAX Data Controls GridView with ID="gdvRecommendation".
Sometimes when I browse to the page I get the following exception:
Script control 'gdvRecommendation' is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors().
Parameter name: scriptControl
My ScriptManager defined in the master page before the content place holder.
This exception doesn't happened always.
I use CustomerDetails.ascx user controls in other pages and it works great.
Can anyone explain me the problem and what can be the solution?
Edit:
Here is the GridView usage in CM.ascx:
<td valign="top" style="height: 150px;">
<div id="divCMMessage"></div>
<div id='divRecommendation' style="width: 100%; display: inline; overflow: auto;">
<ADC:GridView ID="gdvRecommendation" Width="100%" runat="server" CellSpacing="0" CellPadding="3" HorizontalAlign="Right" ShowHeader="false" RowDataBoundEvent="onRowDataBound_gdvRecommendation">
<RowStyle Height="20px" />
<EmptyDataTemplate>no recommendations</EmptyDataTemplate>
<EmptyDataRowStyle HorizontalAlign="Right" BorderWidth="0" />
<Columns>
<ADC:GridViewImageColumn DataImageUrlField="IndImageUrl" HeaderText="" ItemStyle-Width="25px" ItemStyle-HorizontalAlign="Center"></ADC:GridViewImageColumn>
<ADC:GridViewTemplateColumn HeaderText="">
<ItemTemplate>
<asp:Label ID="TreatName" runat="server" Text=""></asp:Label>
</ItemTemplate>
</ADC:GridViewTemplateColumn>
<ADC:GridViewTemplateColumn HeaderText="">
<ItemTemplate>
<asp:Label ID="TreatType" runat="server" Text=""></asp:Label>
</ItemTemplate>
</ADC:GridViewTemplateColumn>
</Columns>
</ADC:GridView>
</div>
</td>
The CustomerDetails.ascx is inside a MultiView (on MyPage.aspx).
I had a similar problem myself and this post helped me to understand my errors:
==============================================
Script control 'ControlName' is not a registered script control
So you're here because you got the following error.
Script control 'ControlName' is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors().
Parameter name: scriptControl
  
I myself have done a fair bit of googling on this, and there are many
solutions given all over the net. unfortunately these are all very
scenario specific solutions. Some people get their answers, and the
others, like me, don't.
Answer:
You are changing the visibility of a control at the wrong stage of the
page life cycle.
Description:
If you are changing the visibility of a control, you should always do
it during, or before the PreRender event. If you do it after (i.e. in
a End handler of an async task or during PreRenderComplete) you might
run in to this issue.
This is not an issue for simple controls such as buttons or text
boxes. But it will have adverse effects on controls such as grids.
When I say changing the visibility it could be any one of the
following situations
Having visible=false of a control during the early stages of the life cycle and being changed to visible=true during an end handler or PreRenderComplete
Changing the selected view of a MultiView during an end handler or PreRenderComplete
Any other situation where the control may not be visible during the earlier stages of the page life cycle which are set to be visible during the latter stage
 
Reason:
Purely
from my understanding, ASP.NET does not render the scripts or the HTML
related to a control if it is not being shown to the user. The
registering of script controls which is mentioned in the exception
seem to happen during an early stage of the life cycle. if the control
is not visible at this stage, this registration is skipped for that
control. If it's made to be visible at a latter point, you get
yourself a control without some of the relevant scripts.
Anyway this is what I have understood. I may be wrong. But if you come
across this issue, it will definitely help you to check for controls
which are changing visibility at different points of the life cycle.
You will be able to identify your specific problem by doing this and
then come up with a solution on your own.
Hope this information helps some one.
============================
Source
I faced same problem recently, above solution did not work for me. I was Hiding a control and later making it visible in PreRender based on some condition check. Hiding was working fine but when I was making it visible again, it was giving me the same error.
below is What worked for me is-
ScriptManager sm = ScriptManager.GetCurrent(Page);
sm.RegisterScriptControl(control_name);
Then making the control visible resolved my issue.
control_name.Visible = true;
Hopefully it may help someone facing this issue.
I had a similar issue with AJAX, and amusingly it occured only when in 'Debug' mode. In release mode, everything works fine. I have not reached to a conclusion on it yet.
You may want to give it a shot.
In case of a RadAjaxPanel and loading UserControls, reading the answer from jhfelectric, I came up with the following solution (simple one):
Disable AJAX on load (Me.EnableAJAX = False) and Enable it on PreRender. Because PreRender isnot called when removing a control, and is called after adding a control.
You can get this Exception when you have a RadAjaxManager in a user control that itself is also inside a RadAjaxManager, either directly or as the child of another user control.

Button not processing onClick method

I have a button on an ascx control that calls a method on the onClick event:
<asp:Button id="bUpdateText" onClick="FUpdate" ValidationGroup="Update" CausesValidation="False" Text="Update" cssclass="button" runat="server" />
Normally I use this control on it's own page and the button works. This time round however, I am loading this control into a Div that is present on the home page of my site (that way I can show the contents with a little bit of JQuery). However, when I bring the control in this way, the onClick event doesn't fire and I am not sure what could cause that.
Sorry I don't have any code sample but the nature of the site makes it difficult to provide any that would make sense.
In short, what would stop this event firing now?
p.s I have tried adding validation groups to all other buttons and validation controls on the page and there is only ONE form present on the page.
EDIT: I have only just added the validation stuff in to see if that does anything. By default it has been like this and still didn't work:
<asp:Button id="bUpdateText" onClick="FUpdate" Text="Update" cssclass="button" runat="server" />
As mentioned as well, this works when I use this control on it's own page (loaded directly into Default.aspx) so I don't think the case of onClick matters.
EDIT2: I have just noticed that when I click this button, other validation controls on my page are being triggered even though they have their own DIFFERENT validation group?! Taking these controls out doesn't help though.
Thanks.
I have found out what is causing the issue.
This control that I am now including is called on the Page_Finalize() and I am guessing that by this point the viewstate has forgotten it needs to do anything. Loading this control on the page load sorts it out.
Thanks for looking.
To start, if you set the 'causesValidation' property to false, you do not need a validation group.
Additionally, I believe that ASP cares about case when dealing with the OnClick command.
i.e. it should be OnClick not onClick
Yeah, annoying and small, but that might be your problem
You can use Firebug to see what happen in Update validationGroup. it looks like your page execute only client-side button click because of Update validationGroup.

Entire Page refreshes even though gridview is in an update panel

I have a gridview that is within an updatepanel for a modal popup I have on a page.
The issue is that the entire page refreshes every time I click an imagebutton that is within my gridview. This causes my entire page to load and since I have grayed out the rest of the page so that the user cannot click on it this is very annoying.
Does any one know what I am missing.
Edit: I entered a better solution at the bottom
Make sure you have the following set on the UpdatePanel:
ChildrenAsTriggers=false and UpdateMode=Conditional
do you have ChildrenAsTriggers="false" on the UpdatePanel?
Are there any javascript errors on the page?
I had this problem and came across the following article:
http://bloggingabout.net/blogs/rick/archive/2008/04/02/linkbutton-inside-updatepanel-results-in-full-postback-updatepanel-not-triggered.aspx
My button wasn't dynamically created in the code like in this example, but when I checked the code in the aspx sure enough it was missing an ID property. On adding the ID the postback became asynchronous and started to behave as expected.
So, in summary, check your button has an ID!
Are you testing in Firefox or IE? We have a similar issue where the entire page refreshes in Firefox (but not IE). To get around it we use a hidden asp:button with the useSubmitBehavior="false" set.
<asp:Button ID="btnRefresh" runat="server" OnClick="btnRefresh_Click" Style="display: none" UseSubmitBehavior="false" />
Several months later this problem was fixed. The project I was working in was a previous v1.1 which was converted with 2.0. However, in the web.config this line remained:
<xhtmlConformance mode="Legacy"/>
When it was commented out all of the bugs that we seemed to have with the ajax control toolkit disappeared
Is the Modal Window popped up using the IE Modal window? Or is it a DIV that you are showing?
If it is an IE Modal Pop up you need to ensure you have
<base target="_self" />
To make sure the post back are to the modal page.
If it is a DIV make sure you have your XHTML correct or it might not know what to update.
I would leave the onClick and set it as the trigger for the updatePanel.
That's odd that it works in FF and not IE. That is opposite from the behavior we experience.
UpdatePanels can be sensitive to malformed HTML. Do a View Source from your browser and run it through something like the W3C validator to look for anything weird (unclosed div or table being the usual suspects)
If you use Firefox, there's a HTML validator Extension/AddOn available that works quite nicely.
For reference..
I've also noticed, when using the dreaded <asp:UpdatePanel ... /> and <asp:LinkButton ... />, that as well as UpdateMode="Conditional" on the UpdatePanel the following other changes are required:
ViewStateMode="Enabled" is required on <asp:Content ... /> (I've set it to Disabled in the MasterPage)
ClientIDMode="Static" had to be removed from <%# Page ... />
To prevent post-backs add return false to the onclick event.
button.attribute.add("onclick","return false;");
Sample:
string PopupURL = Common.GetAppPopupPath() + "Popups/StockChart.aspx?s=" + symbol;
hlLargeChart.Attributes.Add("onclick", String.Format("ShowPopupStdControls(PCStockChartWindow,'{0}');return false;", PopupURL));

Resources