This is a migrated thread and some comments may be shown as answers.

Problems adding a RadToolBar to a custom WebControl

0 Answers 53 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 07 Oct 2009, 10:12 PM
I've implemented a client facing web-portal which uses several data-bound composite WebControls from a library and allows our clients to view their data from within our databases. My problem is with the WebControl that creates and adds a RadToolBar to it's Controls collection during the CreateChildControl override. Seems the only way it will work is if I set the RadToolBar.EnableViewState property to false...otherwise I get the following error at each postback,

        Failed to load viewstate.  The control tree into which viewstate is being loaded must match the 
        control tree that was used to save viewstate during the previous request.  For example, when 
        adding controls dynamically, the controls added during a post-back must match the type and 
        position of the controls added during the initial request.

I have another WebControl in the same library that adds a RadMenuBar the same way and it works fine...example, this fails at postback unless I uncomment the bolded statement,

    public class MyWebControl : WebControl, INamingContainer
    {
        protected override void CreateChildControls()
        {
            this.Controls.Clear();

            RadToolBar toolBar = new RadToolBar();
            toolBar.ID = "MyToolBar";   
            //toolBar.EnableViewState = false;

            this.Controls.Add( toolBar );

            base.CreateChildControls();
        }
}

...yet this works fine
    public class MyWebControl : WebControl, INamingContainer
    {
        protected override void CreateChildControls()
        {
            this.Controls.Clear();

            RadMenu menu = new RadMenu();
            menu .ID = "MyMenu";   

            this.Controls.Add( menu );

            base.CreateChildControls();
        }
}


Anyone know what the problem is??

 

No answers yet. Maybe you can help?

Tags
ToolBar
Asked by
Mark
Top achievements
Rank 1
Share this question
or