System.InvalidOperationException: Script controls may not be registered after PreRender.

2 posts, 0 answers
  1. Martín
    Martín avatar
    2 posts
    Member since:
    Mar 2008

    Posted 16 Apr 2008 Link to this post

    Greetings!

    I'm developing a little Web application and use the RadDock as my base classes. I override OnPreRender and Render for RadDockZone.

    What I'm trying to do is dynamically add the RadDockLayout based on a column structure; I mean, I have a button to add a RadDockLayout to my default ASP.NET page, and I pass a column count, with this I create my RadDockZones. If I pass 2 columns, the RadDockLayout will have 2 RadDockZones. Everything is fine here, the problem comes when I want to add a RadDock to any of my RadDockZones. I use this as guide to my code.

    1. The page is loaded, then I type the Id of the RadDockLayout and asign it a number of columns, then I click the button and create them. The RadDockLayout is inside an UpdatePanel (updater). The zones are shown in the page fine.
    2. I add a RadDock to any zone and when goes to the OnPreRender in my RadDockZone derived class it throws the exception.

    When I'm debugging and reach for the overriden OnPreRender in the RadDockZone derived class, in the line of base.OnPreRender( e ),  it throws a System.InvalidOperationException: Script controls may not be registered after PreRender.

    Here is some code in the RadDockZone derived class:

    protected

    override void OnPreRender( EventArgs e )
    {
        if ( !DesignMode )
        {
            ScriptManager scriptManager = ScriptManager.GetCurrent( base.Page );

            if
    ( scriptManager == null )
                
    throw new HttpException();

            
    scriptManager.RegisterScriptControl( this );
        
    }

        base
    .OnPreRender( e ); // The exception occurs here, after I add a RadDock.
    }

    Code in the Default.aspx.cs:

    protected

    void btnAddRdDockDerived_Click( object sender, EventArgs e )
    {
        var rdLayoutDerived = PageState;
        var rdDockDerived= CreateRdDockDerived( txtRddDerivedName.Text );

        rdLayoutDerived.Zones[
    0].DocksDerived.Add( widget );
        rdDockDerived.Dock( rdLayoutDerived.Zones[0] );

        CreateSaveStateTrigger( widget );
        PageState = rdLayoutDerived ;
    }

    protected

    override void OnPreRender( EventArgs e )
    {
        base.OnPreRender( e );
        
        var
    rdLayoutDerived = PageState;

        if
    ( rdLayoutDerived != null )
        
    {
            updater.ContentTemplateContainer.Controls.Add( rdLayoutDerived );
            PageState = rdLayoutDerived ;
        }
    }

    PageState is a property that saves the RadDockLayout and its children in the session.

    I thank to any help that anyone can give me.

  2. Sophy
    Admin
    Sophy avatar
    636 posts

    Posted 21 Apr 2008 Link to this post

    Hi Martín,

    Thank you for contacting us.

    The problem you experience most often occurs when the OnPreRender method of the page is overridden and the base.OnPreRender(e) is not called. From the code snippets you have sent us I am not able to find the exact reason for experiencing the error you mention. That is why, I would like to request for a simple running project which reproduces the issue so that we can test it locally, research the problem and help you solve it. 

    You will need to open a support ticket in order to have the right to attach files. I reviewed your profile and noticed that currently you are not allowed to open support tickets. Please, download a trial version of the RadControls for ASP.NET AJAX suite and you will have the right to open a support ticket. For your convenience I have attached a screenshot which instructions how to open a support ticket.

    Kind regards,
    Sophy
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top