0

Hey guys check this out ...

<asp:TabContainer ID="jkhgjkgh" runat="server">
    <asp:TabPanel ID="jkkljhgh" runat="server" HeaderText="sdkl;fgjl;kgjdf">
        <ContentTemplate>
            <asp:Button ID="jhgkjgh" runat="server" Text="Button" onclick="Button1_Click" />
        </ContentTemplate>
    </asp:TabPanel>
    <asp:TabPanel ID="jkgh" runat="server" HeaderText="gjdkl;gjdf;g" Visible="false">
        <ContentTemplate>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropDownSelect">
                <asp:ListItem Text="test" />
                <asp:ListItem Text="test" />
                <asp:ListItem Text="test" />
                <asp:ListItem Text="test" />
            </asp:DropDownList> 
        </ContentTemplate>
    </asp:TabPanel>

nothing crazy ... just a tabcontainer with a couple of panels on it the second is hidden.

now we go to the code behind ...

    protected void Button1_Click(object sender, EventArgs e)
    {
        TabPanel p = new TabPanel();

        p.ContentTemplate = jkgh.ContentTemplate;

        jkhgjkgh.Tabs.Add(p);
    }

    protected void dropDownSelect(object sender, EventArgs e)
    {
        int i = 0;
    }

Here's where it all goes horribly wrong ...

I click the button on the first tab panel to create a new tab that has the template defined in my hidden panel, i then go to that panel and change the selection in the drop down ....

It does a postback but the drop down event is never raised ....

Any ideas ???

War
  • 8,539
  • 4
  • 46
  • 98

2 Answers2

1

The problem is that you cant dynamically copy the hidden templated tabpanel and add a new one in to the collection. Apparently the tabcontainer control doesn't allow for this without a lot of "hacking around".

I'm not entirely sure why but it seems that ITemplate types don't clone well for event handling.

War
  • 8,539
  • 4
  • 46
  • 98
0

I think it might be because your TabContainer does not have AutoPostBack set to true.

Hugo
  • 567
  • 1
  • 8
  • 18
  • AutoPostBack (as i understand it) determines weather the control should postback or wait until something else posts back to raise events ... in this case apostback is actually happening but the dropdown eventhandler is not being called ... suffice to say I have tried this. – War Jun 10 '11 at 12:31