Script control is not a registered script control - asp.net

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.

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 !!!

Gridview inside UpdatePanel, paging/sorting doesn't work ONLY when using MasterPage

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.

ASP.NET 2 Control Properties Databinding does not always work

I've got the beautiful task at hand to look at some nice legacy asp.net 2 code and implement some new controls.
It's my first attempt at asp.net (the classic one, i've experimented with mvc a bit) so i am not too fond of it.
Right now i am trying to understand why a databinding sometimes works and a similar binding wont work on another page.
<asp:ImageButton ID="SaveAsPDFButton" runat="server"
ImageUrl='<%#GetPdfIconSmallPath() %>'
ToolTip='<%$ Resources:SaveAsPDFButton.Text %>'
CausesValidation="false" />
While the Tooltip gets evaluated and set, the ImageUrl of this control wont be set. The function is not getting executed. I've tried all, even disabling ViewState on it.
On other places, this same code however works just fine, like this small snippet here which does exactly what you might expect it to do:
<asp:HyperLink ID="InvHl" runat="server">
<asp:Image ID="Img1" ImageUrl='<%#GetPdfIconSmallPath() %>' runat="server" />
</asp:HyperLink>
Same thing occurs with the Visible Property of an ASP:Panel i have on other places in this page.
Any ideas on how to get this working appreciated!
We didnt really solve the problem but switched to the newest version of ASP.NET which does not show such a strange behaviour.

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.

Trying to self contain pop ups which use the AjaxToolkit ModalPopUpExtender

I have 3 different kinds of ajax popups that need to exist across my site. I was hoping that I could simply create a user control for each one and place the panel and modal popup extender inside each one but this doesn't seem to be working. Has anyone tried this before or do you have a recommendation as to how I can avoid duplicate code for each pop up on different pages? Thanks!
Ah I figured out my issue with the User Control I believe.
The ModalPopUpExtender requires the TargetID property to be set otherwise an error occurs. Since this is sitting in a UserControl I just created a dummy link button that doesn't do anything and I set the property visible to false.
<asp:LinkButton ID="lnkBlank" runat="server" Visible="false" />
<asp:Panel ID="plContainer" style="display: none;" runat="server">
Hello?
</asp:Panel>
<cc1:ModalPopupExtender ID="mpe" runat="server"
BehaviorID="test"
TargetControlID="lnkBlank"
PopupControlID="plContainer" />
Apparently it doesn't appreciate that and the moment I set the visible property to true it started working. Not sure what the reasoning is for a TargetID since, I would think, most pop ups could be called from multiple links about the page. Perhaps I'm still not entirely clear on how this control is supposed to be used.
One option would be to write the popups in a asp.net user control (a .ascx page) and include that on the pages you need the popups. Have a public method in the ascx page that will show the popup, and call it from the parent page when you need to. If you already have a script manager on the parent page, you can't have a second one in the ascx page, but other then that there shouldn't be anything that would stop this from working. Hope this helps!
edit: here's what my modal popup extender control looks like...
<cc1:ModalPopupExtender
ID="mpeClassroom"
BackgroundCssCLass="modalBackground"
runat="server"
CancelControlID="lbClose"
OnOkScript="onOk()"
TargetControlID="Button1"
PopupControlID="pnlClassroom">
</cc1:ModalPopupExtender>
in my code behind page, my method just calls mpeClassroom.Show();
The problem with hidden link as TrgetControlID is that; when u set its visibility as false, server doesn't render it as well. PopExtender then cannot find control on the page.
Instead of setting its visibility to false, try to apply a style with display:none. This should work !

Resources