/// <summary>
/// Daniel Balla's Weblog - Various posts
/// on .NET Development, ASP.NET, Agile,
/// TDD, Architecture, SQL and others.
/// </summary>
[Serializable]
class Blog<T> where T : ASP.NET, Ajax, WCF, WF, new()
{
}
Wednesday, November 22, 2006
Script controls may not be registered before PreRender
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;
}
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
{
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;
}
Labels: ASP.NET

7 Comments:
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, at Thursday, November 23, 2006 5:46:00 AM GMT
Thank you, this fixed my problem too!
By
thomas, at Thursday, February 22, 2007 9:26:00 AM GMT
Thank you very much,
this article surely saved my time
By
Evgeny, at Wednesday, August 1, 2007 3:07:00 PM BST
I will add to the list of praise on this one.
Thanks!
By
Anonymous, at Wednesday, August 15, 2007 8:19:00 PM BST
Thanks dude, You saved me a lot of time. If you ever come to visit Mexico, I'll buy you a beer =)
By
Manuel, at Thursday, August 30, 2007 2:00:00 AM BST
There you GO!!!!!!! thanks a lot! you saved my day
By
Anonymous, at Friday, September 21, 2007 6:43:00 PM BST
Thanks Lot, This article is really healpful
By
Anonymous, at Tuesday, June 3, 2008 7:16:00 PM BST
Post a Comment
<< Home