TabContainer实现服务器端回传

作者:互联网   出处:控件中国网   2014-11-05 19:04:59   阅读:1

TabContainer实现服务器端回传

TabContainer要实现服务器端回传,出来在后台实现 OnActiveTabChanged 事件外,还需要在前台实现 OnClientActiveTabChanged 事件,这是关键。

<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true">
    <contenttemplate>
        <ajaxToolkit:TabContainer runat="server" ID="Tabs" Height="480px" Width="100%"
            OnClientActiveTabChanged="activeTabChanged"
            OnActiveTabChanged="Tabs_ActiveTabChanged">
            <ajaxToolkit:TabPanel runat="Server" ID="Panel1" HeaderText="我的消息">
                <ContentTemplate>
                ***
                </ContentTemplate>
            </ajaxToolkit:TabPanel>
            <ajaxToolkit:TabPanel runat="Server" ID="Panel2" HeaderText="已发消息">
                <ContentTemplate>
                    ***
                </ContentTemplate>
            </ajaxToolkit:TabPanel>
        </ajaxToolkit:TabContainer>
    </contenttemplate>
    <triggers>
        <asp:AsyncPostBackTrigger ControlID="Tabs" EventName="ActiveTabChanged" />
    </triggers>
</asp:UpdatePanel>

<script language="javascript" type="text/jscript">
function activeTabChanged(sender, e)
{
    __doPostBack('<%= Tabs.ClientID %>', sender.get_activeTabIndex());
}
</script>


后台.cs代码:


protected void Tabs_ActiveTabChanged(object sender, EventArgs e)
{
    switch (Tabs.ActiveTabIndex)
    {
        case 0:
            BindGrid();
            break;
        case 1:
            BindGrid2();
            break;
        case 2:
            Message.Text = "";
            break;
        default:
            break;
    }
}

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat