Friday, March 16, 2007

Extender controls may not be registered before PreRender

Today, I have added new AjaxControlToolkit controls to Velodoc pages and I got exception “Extender controls may not be registered before PreRender” from running a page.

All our pages derive from our own WebPage class which derive from the standard Page class. WebPage provides features like custom error handling and QueryString parsing into page properties.

The page where we had the new extender control had the following method:

protected override void OnPreRender(EventArgs e)
{
//The following line is required, otherwise you get "Extender controls
//may not be registered before PreRender."
base.OnPreRender(e);

//Some code that displays errors on postbacks
...
}

The solution to the problem above is to add base.OnPreRender(e); at the beginning of the method.

9 comments:

Noffie said...

Aha! Yours and the next few blogs that turn up when you google "Extender controls may not be registered before PreRender" were spot on. One thing to note: I didn't override OnPreRender() in the page that was throwing the error, so I thought I must have a different problem. Then I looked at our BasePage class (the base class for all our pages) and that's where it was happening!

Anonymous said...

Excellent work!Thanks a ton!

Anonymous said...

Thanks for sharing! Yours was the first link I tried and it solved my problem in a minutes. My lucky day!

To add a bit... I only had to add this to my application pages. The Master Pages not require it.

Regards,
-Jeff

Unknown said...

Saved another couple of hours searching... Thanks a million!

TravelOnnn said...

I have included the code but still facing the error... what is the exact cause for this... No success yet.

Jayant Pawar said...

thank U very much

Ashish said...

provided solution not working doe me dude

Ashish said...
This comment has been removed by the author.
Dyslexicanaboko said...

When I got that error I almost pulled my hair out. I knew it had to do with the PreRender handler/method, but holy crap how annoying. Thanks!