在按钮单击中启用和禁用ajax tabcontainer中的选项卡

时间:2012-08-20 04:44:40

标签: asp.net ajax tabcontrol tabcontainer

我在asp.net应用程序中使用ajax选项卡容器,有2个选项卡1.第一个选项卡有gridview,第二个选项卡有添加新项目表单。 在rowcommand上单击我在第二个选项卡中获取所有值,单击编辑我启用所有控件进行编辑。 在此期间,我想限制用户导航到第一个标签,直到他点击 GotoGrid 按钮。 怎么实现这个? 如果我使用

  

tab_name.enable = FALSE;

即使所有按钮和控件都被禁用。 请帮忙!

1 个答案:

答案 0 :(得分:1)

<asp:HiddenField runat="server" ID="disabledPaneIndex" />
<ajaxToolkit:Accordion runat="server" ID="Accordion1" >
     <Panes>
          <ajaxToolkit:AccordionPane runat="server" ID="Pane1" >
               <Header>
                    Pane 1
               </Header>
               <Content>
                    <asp:Button runat="server" ID="SwitchToPane2Button" Text="Go To Pane2" OnClick="SwitchToPane2Button_Click" />
               </Content>
          </ajaxToolkit:AccordionPane>
          <ajaxToolkit:AccordionPane runat="server" ID="Pane2">
               <Header>
                    Pane 2
               </Header>
               <Content>
                    <asp:Button runat="server" ID="SwitchBackButton" Text="Go Back" OnClick="SwitchBackButton_Click" />
               </Content>
          </ajaxToolkit:AccordionPane>
     </Panes>
</ajaxToolkit:Accordion>

服务器代码:

protected void SwitchToPane2Button_Click(object sender, EventArgs e)
{
    Accordion1.SelectedIndex = 1;
    disabledPaneIndex.Value = "0";
}

protected void SwitchBackButton_Click(object sender, EventArgs e)
{
    disabledPaneIndex.Value = string.Empty;
    Accordion1.SelectedIndex = 0;
}

JavaScript(位于ScriptManager控件

之后
function pageLoad() {
     var accordion = $find("<%= Accordion1.ClientID %>_AccordionExtender");
     accordion.remove_selectedIndexChanging(selectedIndexChanging);
     accordion.add_selectedIndexChanging(selectedIndexChanging);
}

function selectedIndexChanging(sender, args) {
     var disabledIndexValue = parseInt($get("<%= disabledPaneIndex.ClientID %>").value);
     if (!isNaN(disabledIndexValue) && args.get_selectedIndex() === disabledIndexValue) {
          args.set_cancel(true);
     }
}