losing viewstate in child controls when writing custom control

Discussion in 'ASP .Net' started by spacehopper_man, Oct 12, 2005.

  1. 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:Tab id="tab1" text="Tab1">.....controls go here...</cc:Tab>
    <cc:Tab id="tab2" text="Tab2">.....controls go here...</cc:Tab>

    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

    // doing this destroys viewstate for child controls

    // but doing this is fine

    spacehopper_man, Oct 12, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.