losing viewstate in child controls when writing custom control

S

spacehopper_man

hi - I am writing a "tab" control.

- but it's losing the viewstate of the content pane when I switch
between tabs.

can anyone shed any light on why I'm losing ViewState based on my
simple example below?


- if I put the tabs at the top of the screen viewstate is lost -
whereas it's fine if I put the tabs at the bottom.

a typical aspx page will look like this:

<cc:TabPanel>
<cc:Tab id="tab1" text="Tab1">.....controls go here...</cc:Tab>
<cc:Tab id="tab2" text="Tab2">.....controls go here...</cc:Tab>
</cc:TabPanel>

my techique is to create a TabPanel custom control - this simply
prepends some controls (that represent the tabs) to it's list of child
controls. There is also a "Tab" custom control that does very little.

I can boil the problem down do the following in the TabPanel control as
per the comments:

protected override void CreateChildControls()
{

Tab[] tabs = getTabs();
foreach (Tab tab in tabs)
{
// this linkbutton represents a "tab"
LinkButton linkButton = new LinkButton();
linkButton.ID = "LinkButton" + tab.ID;
linkButton.Text = tab.ID;
linkButton.CommandName = tab.ID;
linkButton.Click += new EventHandler(linkButton_Click);

// add the "tab" to the list of controls in the tab
panel

// doing this destroys viewstate for child controls
this.Controls.AddAt(0,linkButton);

// but doing this is fine
this.Controls.Add(linkButton);
}

base.CreateChildControls();
..
..
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top