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

Error: Script controls may not be registered before PreRender

4 Answers 527 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 02 Mar 2010, 10:09 PM
I've got a .NET 2.0 ASP.Net web app with a master page and I'm trying to add Ajax features to it. I've added a RadScriptManager to the master page and it runs. As soon as I add a RadAjaxManager or a RadAjaxPanel to the master page, it dies upon start up with the following error:
Script controls may not be registered before 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 before 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 before PreRender.] 
   System.Web.UI.ScriptControlManager.RegisterScriptControl(TScriptControl scriptControl) +236 
   System.Web.UI.ScriptManager.RegisterScriptControl(TScriptControl scriptControl) +99 
   Telerik.Web.UI.RadAjaxManager.OnPreRender(EventArgs e) +97 
   System.Web.UI.Control.PreRenderRecursiveInternal() +86 
   System.Web.UI.Control.PreRenderRecursiveInternal() +170 
   System.Web.UI.Control.PreRenderRecursiveInternal() +170 
   System.Web.UI.Control.PreRenderRecursiveInternal() +170 
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041 
 
  
 
 
-------------------------------------------------------------------------------- 
Version Information: Microsoft .NET Framework Version:2.0.50727.1873; ASP.NET Version:2.0.50727.1433  

The same thing happens if I add either of the two to the default.aspx page or a .ascx control that is used on the default.aspx page.

What am I doing wrong?

4 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 03 Mar 2010, 09:17 AM
Hi Bob,

Are you calling the Renderer method in your code? Please, review the following forum thread, which elaborate on this topic:
http://www.telerik.com/community/forums/aspnet-ajax/input/bug-report-script-control-may-not-be-registered-after-prerender.aspx

If this information does not help, I'd ask you to post your aspx and code behind (please, do use the Code Formatter tool for this purpose).

Sincerely yours,
Pavlina
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
Bob
Top achievements
Rank 1
answered on 03 Mar 2010, 03:12 PM
Thanks, you've helped me find the offending code. I override the OnPreRender event in my content page:
        protected override void OnPreRender(EventArgs e) 
        { 
            ClientScriptManager cs = this.ClientScript; 
            if (cs != null
            { 
                Type t = typeof(LossDraftDetails); 
                if (!cs.IsClientScriptIncludeRegistered("LossDraftDetails")) 
                { 
                    string JsUrl = cs.GetWebResourceUrl(t, 
                                    "fnLossDraft.LossDraftDetails.js"); 
                    cs.RegisterClientScriptInclude(t, "LossDraftDetails", JsUrl); 
                } 
            } 
        } 
 

so I can register a client script file.

Does this mean that a content page can never override OnPreRender using the RAD Ajax controls?
If so, where am I supposed to register client scripts?


0
Pavlina
Telerik team
answered on 08 Mar 2010, 12:21 PM
Hi Bob,

You need to call  base.OnPreRender(e) in order to override OnPreRender event. Please try to change your code as shown bellow and let me know how it goes.
C#:
protected override void OnPreRender(EventArgs e)  
    {  
        base.OnPreRender(e);
        ClientScriptManager cs = this.ClientScript;  
        if (cs != null)  
        {  
            Type t = typeof(LossDraftDetails);  
            if (!cs.IsClientScriptIncludeRegistered("LossDraftDetails"))  
            {  
                string JsUrl = cs.GetWebResourceUrl(t,  
                                "fnLossDraft.LossDraftDetails.js");  
                cs.RegisterClientScriptInclude(t, "LossDraftDetails", JsUrl);  
            }  
        }  
    }  

Kind regards,
Pavlina
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
Bob
Top achievements
Rank 1
answered on 08 Mar 2010, 02:34 PM
That will do it. Thank you for your help.
Tags
Ajax
Asked by
Bob
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Bob
Top achievements
Rank 1
Share this question
or