Skip navigation.

Gordon Segal's Advice to An EntrepreneurAll recent postsCancelling Event Bubble Interferes With MS AJAX On Postback

Extender/Script controls may not be registered before PreRender

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.

Comments

Comment permalink 1 Shree Menon |
Yes you did -- Thanks a lot....
Comment permalink 2 Willie Brits |
Thanks you did save me an hour or two
Comment permalink 3 Christoph |
Thanks. You did indeed save me some time.
Comment permalink 4 Chris N |
I'll add to the comments here... yes, that did save a lot of time and a lot of head-desk action...

Thanks!
Comment permalink 5 Pankaj Mittal |
Cool.. thanks.
Comment permalink 6 Stephanie |
Thank you for posting this.
Comment permalink 7 sunfly |
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.
Comment permalink 8 Irshaad |
sunfly,
have you managed to fix your problem?
I have the same problem and need a solution.
Comment permalink 9 surya |
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
Comment permalink 10 Milan Negovan |
Unfortunately, I can't guess the source of error. Perhaps, overriding OnPreRender would be a good idea. :)
Comment permalink 11 Surya |
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
Comment permalink 12 Ivan |
Thanks to you and Daniel Balla ;)
Comment permalink 13 Sean |
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.
Comment permalink 14 Dylan Baxter |
Yep, you saved me quite the headache! Thank you!
Comment permalink 15 John Gilmore |
Yes, you saved me alot of debug time! Thanks!
Comment permalink 16 Sandman |
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.
Comment permalink 17 Eric Ouellet |
Thanks a lot... yes it saved me probably lots of hours !!!
Very nice to share the info !!!
Comment permalink 18 ajish |
thanks ......
Comment permalink 19 Douglas |
Thanks!
Comment permalink 20 erkan |
Thank you!. You saved me a lot of research / debug time
Comment permalink 21 Bernhard |
Add me to the list of people you just saved a few hours of debugging.
Comment permalink 22 Addis abebayehu |
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
Comment permalink 23 shameem |
Thanks a lot !!! It worked even for me!!! :)
Comment permalink 24 Pradip |
Thanks,

It is work like a charm....
Comment permalink 25 Rads |
Thanks it really hepled me.
Comment permalink 26 Balaji |
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.
Comment permalink 27 Krishan Ariyawansa |
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.
Comment permalink 28 Ignacio |
@ Krishan Ariyawansa

You are a life savior!

I took me 8 hours!

Thanks!!!!
Comment permalink 29 SeyyedKarim |
tanks ALOT

Emails and Notifications

Would you like to be notified when somebody responds to this post?  Would you like to have these comments emailed to you?

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):