Monday, February 06, 2012     •  Login
 
   
 
   
   
   
 
 
     
 
   Welcome to my blog! Minimize
Nov 22

Written by: Daniel Balla
Wed, 22 Nov 2006 18:55:59 GMT

This is neither a very common scenario nor a major finding, just a small reminder/warning to spare you a little debugging for one of those things that are fairly obvious yet could take some time to see.
While helping a friend figure out why his ASP.NET no longer works after "atlasising" it I came across this issue:
The page was throwing the following exception:

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.]
Microsoft.Web.UI.ScriptControlManager.RegisterScriptControl(TScriptControl scriptControl) +144
Microsoft.Web.UI.UpdateProgress.OnPreRender(EventArgs e) +140
System.Web.UI.Control.PreRenderRecursiveInternal() +77
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360



As the page worked before it had the atlas references and an update panel added (and out of laziness) instead of properly reading the source code I proffered to google the error and the only relevant result was http://forums.asp.net/thread/1471314.aspx where the suggestion was that an older version of the DLL might be cached somewhere. Here is where I went wrong and spent a lot of time clearing and rebuilding. On a second look, I found that the page's OnPreRender method was overridden and it didn't call the base OnPreRender method therefore loosing some handlers. Obviously this mistake didn't do much difference before atlas came into play but it did afterwards because the Atlas ScriptControlManager's RegisterScriptControl method doesn't register the control but after prerender (by checking a flag it sets on prerender)

public void RegisterScriptControl(TScriptControl scriptControl) where TScriptControl: Control, IScriptControl
{
if (scriptControl == null)
{
throw new ArgumentNullException("scriptControl");
}
if (!this._pagePreRenderRaised)
{
throw new InvalidOperationException(AtlasWeb.ScriptControlManager_RegisterScriptControlTooEarly);
}
this.ScriptControls.Add(scriptControl);
}


public void OnPagePreRender(object sender, EventArgs e)
{
this._pagePreRenderRaised = true;
}

Tags:

4 comments so far...

Re: Script controls may not be registered before PreRender

THANK YOU SOOOOO MUCH!!

I went through all my PreRender overrides and made sure I was calling base.OnPreRender(e) (which i wasn't in many places) and that fixed my problem!!!

Thanks again.

By Eric Carlson on   Sun, 22 Jun 2008 19:34:32 GMT

Re: Script controls may not be registered before PreRender

Thanks to your blog, Googling the problem resolved it in about 2 minutes!

By Will Smith on   Wed, 16 Jul 2008 16:21:47 GMT

Re: Script controls may not be registered before PreRender

Thank you, Master!

By Grasshopper on   Fri, 25 Jul 2008 12:50:59 GMT

Re: Script controls may not be registered before PreRender

Thank you very much. :)

By Özgür on   Thu, 04 Jun 2009 06:23:07 GMT

Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment    Cancel  
 
 
     
     
 
   Archives Minimize
 
 
     
     
 
   Search Blog Minimize