views:

523

answers:

3

Please, I am new to webparts and I need help!!

I have a custom web part that I created. I added MS Ajax to it using an UpdatePanel which works fine. I add all my controls to the CreateChildControls method. As soon as I add a UpdateProgress control my page breaks with the following error:

Script controls may not be registered before PreRender

I do not use the OnPreRender event as what other posts suggest. Please, if anyone can give me advice it will be very much appreciated.

Thanks

+1  A: 

You might have forgotten to call the base method of an overrided event, which is not necessarily the OnPreRender event.

Check if the OnInit or OnLoad events are calling their base.On[...] method, e.g.:

protected override void OnLoad(EventArgs eventArgs)
{
    base.OnLoad(eventArgs);

    // your code...
}
Pedrin
+1  A: 

Hi, I encountered similar problem before, try to call EnsureChildControls method inside your on init method override. It should be called by system automatically, but sharepoint likes to forget about it from time to time.

Like this:

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        EnsureChildControls();
    }
drax
A: 

I tried the solution proposed by drax (i.e., adding EnsureChildControls() to OnInit()), and it worked like a charm for me. I wanted to just vote up his answer, but I guess I don't have enough reputation points for that. Sorry to respond to the limit in this fashion, but I really wanted to give him credit for helping me solve a bug I've been agonizing over for a couple of hours now.

-Ash

Ash