Extender/Script controls may not be registered before PreRender
Posted in Development
If you receive an error similar to this, it’s time to look for a missing
call to base.OnPreRender.
If you override OnPreRender(EventArgs e) in a custom control, the conventional wisdom says you need to remember to call base.OnPreRender(e). Recently, I ran into this issue and found out the hard way that the page which hosts your control also must call base.OnPreRender in its OnPreRender (if you override it at all).
I hope I saved someone an hour or two of debugging. Thanks to Daniel Balla for pointing me in the right direction.
29 comments
Willie Brits
on December 20, 2007
Thanks you did save me an hour or two
Christoph
on February 13, 2008
Thanks. You did indeed save me some time.
Chris N
on February 25, 2008
I'll add to the comments here... yes, that did save a lot of time and a lot of head-desk action...
Thanks!
Pankaj Mittal
on March 11, 2008
Cool.. thanks.
Stephanie
on April 4, 2008
Thank you for posting this.
sunfly
on April 19, 2008
Could you help me ? I make a custom control which have a ScriptManager and a CalendarExtender .They were defined in the CreateChildControls.I didnot override OnPreRender. But I still had this
error(Extender controls may not be registered before PreRender.).
What's wrong?
I am sorry.I am a chinese.My english is bad.
Thanks.
Irshaad
on May 5, 2008
sunfly,
have you managed to fix your problem?
I have the same problem and need a solution.
surya
on July 13, 2008
Hi Milan,
I didnt override the prerender event but i do get the same error, can u guess the source of error,
I am using Calendar Extender Control in .ascx & while implementing this in a sharepoint site i get this error.
thanks ,
Surya
Milan Negovan
on July 14, 2008
Unfortunately, I can't guess the source of error. Perhaps, overriding OnPreRender would be a good idea. :)
Surya
on July 15, 2008
Milan,
Thanks, I did tried your suggestion, thing is that i am not using Prerender event in my Usercontrols altogether. So there might be something i have left out.. Will try & find the cause & Share things with you.
Also it works fine in Few usercontrols & shows up such error in other user controls
thanks for ur time...
Surya
Ivan
on July 18, 2008
Thanks to you and Daniel Balla ;)
Sean
on August 6, 2008
Thanks Milan,
My user control started showing this error when I moved it onto an UpdatePanel. I got it working after I removed a 'using statement' referencing 'Page' during the 'OnLoad()' event, e.g.:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Page parentPage = this.Page as Page;
using (parentPage)
{
}
}
The using statement wasn't a good idea in the first place but I'd like to know what it was doing to page to cause the error.
Sean.
John Gilmore
on September 23, 2008
Yes, you saved me alot of debug time! Thanks!
Sandman
on October 11, 2008
You may also find that you will get this error if you have a control on your page (such as a login view) that you have commented out in your source code. Remove or uncomment your code to correct this error.
Eric Ouellet
on February 3, 2009
Thanks a lot... yes it saved me probably lots of hours !!!
Very nice to share the info !!!
ajish
on February 10, 2009
thanks ......
Douglas
on June 12, 2009
Thanks!
Bernhard
on August 11, 2009
Add me to the list of people you just saved a few hours of debugging.
Addis abebayehu
on September 3, 2009
I keep getting this error. I don't understand it. I have my scriptManager on my ascx page. It is already registered. I don't even have an updatePanel. It works when i run it in ASP.Net environment. i get this error when i try to deploy it to sharepoint site.
I will appreciate any help you can provide.
thanks!
Server Error in '/' Application.
--------------------------------------------------------------------------------
Extender 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: Extender 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: Extender controls may not be registered before PreRender.]
System.Web.UI.ScriptControlManager.RegisterExtenderControl(TExtenderControl extenderControl, Control targetControl) +635942
System.Web.UI.ScriptManager.RegisterExtenderControl(TExtenderControl extenderControl, Control targetControl) +86
System.Web.UI.ExtenderControl.RegisterWithScriptManager() +146
AjaxControlToolkit.ExtenderControlBase.OnPreRender(EventArgs e) +52
AjaxControlToolkit.MaskedEditExtender.OnPreRender(EventArgs e) +30
System.Web.UI.Control.PreRenderRecursiveInternal() +108
System.Web.UI.Control.PreRenderRecursiveInternal() +224
System.Web.UI.Control.PreRenderRecursiveInternal() +224
System.Web.UI.Control.PreRenderRecursiveInternal() +224
System.Web.UI.Control.PreRenderRecursiveInternal() +224
System.Web.UI.Control.PreRenderRecursiveInternal() +224
System.Web.UI.Control.PreRenderRecursiveInternal() +224
System.Web.UI.Control.PreRenderRecursiveInternal() +224
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394
shameem
on September 5, 2009
Thanks a lot !!! It worked even for me!!! :)
Pradip
on September 14, 2009
Thanks,
It is work like a charm....
Rads
on September 22, 2009
Thanks it really hepled me.
Balaji
on September 30, 2009
Hi
This would help if you are adding scriptmanager dynamically
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (ScriptManager.GetCurrent(Page) == null)
{
ScriptManager scriptManager = new ScriptManager();
Page.Form.Controls.AddAt(0, scriptManager);
}
}
Hope this helps.
Krishan Ariyawansa
on October 13, 2009
For "Surya" and others who didn't use prerender but still gets an error.
If you have used "CreateChildControls", call "EnsureChildControls();" on "OnInit" event. This will work like a charm.
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
EnsureChildControls();
}
Credit should go to the following link;
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/3a597eef-f1ef-4485-99b7-9afb2a161222?prof=required&lc=1033
I'm just pointing to he right direction.
Ignacio
on January 26, 2010
@ Krishan Ariyawansa
You are a life savior!
I took me 8 hours!
Thanks!!!!
SeyyedKarim
on March 1, 2010
tanks ALOT

Shree Menon
on August 23, 2007
Yes you did -- Thanks a lot....