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

Script controls may not be registered before PreRender

1 Answer 544 Views
ScriptManager and StyleSheetManager
This is a migrated thread and some comments may be shown as answers.
Graeme
Top achievements
Rank 1
Graeme asked on 09 Mar 2012, 03:01 PM
Ok, I'm at the bottom of the pit of despair!
Have tried for days to resolve this problem, so maybe hoping someone here can help. I've searched the web and tried all the advice given, to no avail. Here is the problem.

I built a local project with RAD grid, cloud, combos etc and it worked fine.  However, when I integrated it into out CMS, the problems started.  The man error message is:

Script controls may not be registered before PreRender


The problem is something to do with this piece of code:
<telerik:RadScriptManager ID="RadScriptManager1" EnableHandlerDetection="false" runat="server">
</telerik:RadScriptManager>


The pages where I've tried this :
1. The master page
2. The ascx page

Doesn't matter where I position this line of code, I still get either the above error message.  I've also tried these 2 different code blocks (not at the same time obviously) in the code behind of the ascx page:

  
protected override void OnInit(EventArgs e)
{
    if (ScriptManager.GetCurrent(this.Page) == null)
    {
        ScriptManager scriptManager = new ScriptManager();
        scriptManager.ID = "myScriptManager";
        scriptManager.EnablePartialRendering = true;
        this.Page.Form.Controls.Add(scriptManager);
    }
    base.OnInit(e);
}
 
protected override void OnPreRender(EventArgs e)
{
    if (ScriptManager.GetCurrent(this.Page) == null)
    {
        ScriptManager scriptManager = new ScriptManager();
        scriptManager.ID = "myScriptManager";
        scriptManager.EnablePartialRendering = true;
        this.Page.Form.Controls.Add(scriptManager);
    }
    base.OnPreRender(e);
}

Here is the stack trace:
[InvalidOperationException: Script controls may not be registered before PreRender.]
   System.Web.UI.ScriptControlManager.RegisterScriptControl(TScriptControl scriptControl) +348689
   System.Web.UI.ScriptManager.RegisterScriptControl(TScriptControl scriptControl) +66
   Telerik.Web.UI.RadWebControl.RegisterScriptControl() +42
   Telerik.Web.UI.RadWebControl.ControlPreRender() +15
   Telerik.Web.UI.RadFormDecorator.ControlPreRender() +464
   Telerik.Web.UI.RadWebControl.OnPreRender(EventArgs e) +22
   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.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842


I'm pretty much as my wits end with this. Any ideas Telerik, community?
Many thanks,
Alan

1 Answer, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 13 Mar 2012, 02:57 PM
Alan:

I'm not sure if you've seen this Telerik forum thread yet, but it has some useful insights from Pavlina in Telerik Admin:

Error: Script controls may not be registered before PreRender

Hope this helps!
Tags
ScriptManager and StyleSheetManager
Asked by
Graeme
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Share this question
or