开发者

AjaxControlToolkit:TabPanel

This control has a property Enabled 开发者_JS百科that acts exactly as Visible behaves i.e. ?.Enabled = false hides the control.

I need to be able to keep all the tabs visible but some to be disabled under code control.

Any hints as to how I can achieve this? Thanks.


Try to set Enabled property for TabPanel.

<ajaxToolkit:TabContainer 
      ID="TabContainer1" runat="server" ActiveTabIndex="0">
        <ajaxToolkit:TabPanel ID="TabPanel1"   runat="server" HeaderText="TabPanel1"></ajaxToolkit:TabPanel>
        <ajaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2"></ajaxToolkit:TabPanel>
        <ajaxToolkit:TabPanel ID="TabPanel3" Enabled="False" runat="server" HeaderText="TabPanel3"></ajaxToolkit:TabPanel>
    </ajaxToolkit:TabContainer>

Or in code-behind,

TabContainer1.Tabs[0].Enabled = false;


Here is one possible solution using client-side scripting. Basically, handle the OnClientActiveTabChanged event for the TabContainer (which fires whenever the active tab is changed). Then, if the tab is one that you don't want the user to use, change the ActiveTabIndex property of the TabContainer back to one that is acceptable.

Tab Container:

<asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1" 
    Height="126px" Width="400px" ClientIDMode="Predictable" 
    onclientactivetabchanged="tabClickCheck" >
    <asp:TabPanel ID="TabPanel1" runat="server" HeaderText="TabPanel1">
    </asp:TabPanel>
    <asp:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2">
    </asp:TabPanel>
    <asp:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
    </asp:TabPanel>
</asp:TabContainer>

Javascript handler:

<script type="text/javascript">
    function tabClickCheck() {
        var tabCont = document.getElementById("<%=TabContainer1.ClientID %>").control;
        var tabInd = tabCont.get_activeTabIndex();
        tabCont.set_activeTabIndex(2);
    }
</script>

This function just sets the ActiveTabIndex to 2, regardless of which tab you clicked (you'll notice I'm also getting the current ActiveTabIndex, but I don't do anything with it - that's just to show you how). Obviously, use whatever logic makes sense for your app =)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜