Ajax TabContainerTabPanels Break postbacks

佐手、 提交于 2019-12-13 05:24:41

问题


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 ???


回答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.




回答2:


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



来源:https://stackoverflow.com/questions/5953006/ajax-tabcontainertabpanels-break-postbacks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!