This is a migrated thread and some comments may be shown as answers.

Script controls may not be registered after PreRender.

11 Answers 718 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Joe Joseph
Top achievements
Rank 1
Joe Joseph asked on 13 Sep 2010, 07:26 PM

I am using Normal telerik radgrid bind.

on OnLoad Event i called load grid functionality.

 

   
  
private void OnLoad()
  
{
  
uxUserList.DataSource = Model.UsersModelList;
  
uxUserList.DataBind();
  
  
}

 

 

it's working fine.

but when i enabled AllowPaging="true" i get the following error.

i am using RadScriptManager on My master page. and Perticular code block is
called inside a user control.

 

 

 

 


 

Server Error in '/Baker.IssueTrackingSystem.Web' Application.

Script controls may not be registered after PreRender.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Script controls may not be registered after PreRender.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Script controls may not be registered after PreRender.]
   System.Web.UI.ScriptControlManager.RegisterScriptControl(TScriptControl scriptControl) +348527
   System.Web.UI.ScriptManager.RegisterScriptControl(TScriptControl scriptControl) +66
   Telerik.Web.UI.RadDataBoundControl.RegisterScriptControl() +43
   Telerik.Web.UI.RadDataBoundControl.ControlPreRender() +15
   Telerik.Web.UI.RadComboBox.OnPreRender(EventArgs e) +25
   System.Web.UI.Control.PreRenderRecursiveInternal() +80
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.AddedControl(Control control, Int32 index) +8682853
   System.Web.UI.ControlCollection.Add(Control child) +80
   Telerik.Web.UI.RadGrid.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +238
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   Telerik.Web.UI.RadGrid.DataBind() +21
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   WebFormsMvp.Web.<>c__DisplayClassa`1.<Register>b__9(Object sender, EventArgs e) +15
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +8699938
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1029

 

 

 

 

 


 

 

11 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 14 Sep 2010, 07:10 AM
Hello Joe,

Looking at the call stack you have pasted, it seems that you are using WebFormsMVP. Therefore, I suspect that the cause for the error you are getting is the way MvpUserControl is implemented. As you may know the class exposes an AutoDataBind property, which by default will cause a call to DataBind on PreRenderComplete event. However, this will eventually recreate all databound controls too late in the page's lifecycle causing IScriptControl implementers to thrown the mentioned exception. Thus, could you set AutoDataBind property to false (inside UserControl's constructor) and see if this makes any difference in the observed behavior.

Greetings,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rob
Top achievements
Rank 1
answered on 15 Feb 2012, 11:06 AM
Rosen, you are my hero!

I am using MVP framework as explained on http://webformsmvp.com/ and tried to data bind a RadGrid (Q2.2011) and got the same 'script controls may not be registered before prerender' error as described by Joe Joseph.

After creating a constructor for my code behind class and setting the boolean AutoDataBind to false I still got the same error.
On the verge of pulling my hair out I noticed that the method Register<T> in the PageViewHost class was called not once (as I was expecting since there was only one UserControl in my project at that point) but twice.

And then it dawned to me; the Page which was carying the UserControl was using the MvpPage implementation, functioning as a container and thus calling the Register<T> method (and data binding) all of it's child controls.

Anyhow, Rosen, thank you once again for your help.

Excellent support from Telerik!
0
Goran Karabeg
Top achievements
Rank 1
answered on 21 Mar 2012, 01:47 PM
And how did you fix the problem Rob?
I have the same problem myself.
Using MVP framework where one user control has another one inside and I get this same error.
Hope this does not means that I have to combine user controls in one big pile of code :).
0
Rob
Top achievements
Rank 1
answered on 21 Mar 2012, 02:09 PM
Hi Goran,

No, you do not have to combine all your user controls in to one big pile of code. Fortunately :-)

You will need to set the property AutoDataBind to false in both MvpUserControl.cs and MvpPage.cs. These two classes can be found (in the original project) in the WebFormsMvp project in the map Web.

Hope this helps.
If you have any more questions, feel free to ask!
0
Goran Karabeg
Top achievements
Rank 1
answered on 21 Mar 2012, 03:02 PM
Hi and thanks for quick response.

Well I did what you said, and now I don't have telerik script error on prerender, but I nothing shows in my radgrid :(.

My scenario is : one big Usercontrol with searchbox and textbox and 5 others usercontrols.
Each of these controls has a presenter, model  and radgrid + mvp:PageDataSource.

Is there any way to bind this thing manually, with having AutoDataBind=true?

Thanx,
-Goran
0
Rob
Top achievements
Rank 1
answered on 21 Mar 2012, 03:06 PM
Hi Goran,

Are you using the OnNeedDataSource event on your RadGrid?
That should do the trick.

If not, could you post you're code / project so I could take a closer look?
0
Goran Karabeg
Top achievements
Rank 1
answered on 21 Mar 2012, 06:41 PM
Hi Rob.

I'v tried with OnNeedDataSource event and while it gets the data from model it does not react when I change the main model(which other model use as a parent container).
There is not much code to post since I am getting data from a web service and use only one telerik databound control  and one datasource control in each user control.
It works well with normal Mvp wiring, all events are firing properly with no need for code behind.

I think that changing the RadGrid binding kind of breaks up the fine logic of MVP pattern.
On the other hand, I have to use Radgrid because of UI complexity that I have to develop so I will have to bind this thing manually somehow.

Thanks for the help.

-Goran
0
Gus
Top achievements
Rank 1
answered on 08 Jul 2013, 09:21 PM
So anybody was successful on getting rid of this error using WebFormsMVP? I have this error and tried everything mentioned here but no success.
0
Rob
Top achievements
Rank 1
answered on 09 Jul 2013, 07:04 AM
Hey Gus,

Yes, back then I was succesful in getting rid of this error. Could you show me what your setup and/or post some code?


Kind regards,
Rob
0
Gus
Top achievements
Rank 1
answered on 09 Jul 2013, 02:31 PM
Hey Rob,

Thanks for your quick response! I was able to figure it out as well by reading and reading and reading your postL

'On the verge of pulling my hair out I noticed that the method Register<T> in the PageViewHost class was called not once (as I was expecting since there was only one UserControl in my project at that point) but twice.

And then it dawned to me; the Page which was carying the UserControl was using the MvpPage implementation, functioning as a container and thus calling the Register<T> method (and data binding) all of it's child controls.'

I turned off AutoDataBind on the right place and it's working now.

Thanks again!

Gus
0
Ashraf
Top achievements
Rank 1
answered on 11 Dec 2013, 10:30 AM
Please call
base.OnPreRender(e);wherever overrding method OnPreRender()
protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);
................................
................................
}


Sky
Top achievements
Rank 1
commented on 06 Aug 2021, 10:33 AM | edited

Hello All,

I am also facing same issue, below is my stack trace, please help... thank you !!

Stack Trace:

[InvalidOperationException: Script controls may not be registered after PreRender.]
   System.Web.UI.ScriptControlManager.RegisterScriptControl(TScriptControl scriptControl) +346
   Telerik.Web.UI.RadDataBoundControl.RegisterScriptControl() +158
   Telerik.Web.UI.RadDataBoundControl.ControlPreRender() +40
   System.Web.UI.Control.PreRenderRecursiveInternal() +132
   System.Web.UI.Control.AddedControl(Control control, Int32 index) +11726032
   Telerik.Web.UI.RadGrid.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +255
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +97
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +208
   Telerik.Web.UI.RadGrid.DataBind() +25
   Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) +3115
   Telerik.Web.UI.Grid.Export.TableViewExporter.ExcelExportRenderForm(HtmlTextWriter nullWriter, Control form) +2356
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +276
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +136
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +47
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +53
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +276
   System.Web.UI.Page.Render(HtmlTextWriter writer) +40
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4239

 

Vessy
Telerik team
commented on 11 Aug 2021, 08:48 AM

Hi Sky,

Are you using the OnNeedDataSource event on your RadGrid or you are calling its DataBind method? If the second is true, try moving the datasource-setting logic to the OnNeedDataSource event and see how it goes?

https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-binding/server-side-binding/programmatic-databinding-using-needdatasource-event

Tags
Ajax
Asked by
Joe Joseph
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Rob
Top achievements
Rank 1
Goran Karabeg
Top achievements
Rank 1
Gus
Top achievements
Rank 1
Ashraf
Top achievements
Rank 1
Share this question
or