Place a button of Asp.net enable code only in a Tabpanel

Asked

Viewed 333 times

1

In the code below:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="buttons">
    <asp:ImageButton ID="btnNew" runat="server" ImageUrl="~/Images/New_6.png" ToolTip="Novo Fornecedor" OnClick="btnNew_Click" />
    <asp:ImageButton ID="btnDelete" runat="server" ImageUrl="~/Images/delete_new.png" ToolTip="Excluir Fornecedor" />
    <asp:ImageButton ID="btnSave" runat="server" ImageUrl="~/Images/save_all.ico" OnClick="btnSave_Click" OnClientClick=" return validate()" ToolTip="Salvar Fornecedor" />
</div>
<%-- <div class="form">--%>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:TabContainer ID="TabFurnisher" runat="server" TabIndex="0" Width="100%" CssClass="ajax__myTab" ActiveTabIndex="1">
            <asp:TabPanel runat="server" HeaderText="Cadastrar Fornecedor" ID="tbSearch">
                <HeaderTemplate>Cadastrar Fornecedor</HeaderTemplate>
                <ContentTemplate>
              <div class="linha">
                       <div class="tab_tr">
                        <div class="fields_credit">
                            <div class="control-group">
                                <asp:Label ID="Label1" runat="server" Text="Escola"></asp:Label><div class="controls">
                                    <asp:DropDownList ID="ddlSchool" CssClass="textbox_search validate[required]" runat="server" Width="365px" Style="margin-left: 1px" AutoPostBack="True"></asp:DropDownList></div>

                            </div>
                        </div>
                        <div class="texto">
                            <div class="control-group">
                                <asp:Label ID="lblName" runat="server" Text="Name"></asp:Label><div class="controls">
                                    <asp:TextBox ID="txtName" runat="server" CssClass="textbox_search validate[required]"></asp:TextBox></div>
                            </div>
                        </div>
                        </div>
                        <br />
                        <br />
                        <br />
                        <div class="fieldssd">
                            <div class="control-group">
                                <asp:Label ID="lblDescricao" runat="server" Text="Descrição"></asp:Label><div class="controls">
                                    <asp:TextBox runat="server" CssClass="textbox_search validate[required]" Height="40px" Width="500px" ID="txtDesciption" TextMode="MultiLine"></asp:TextBox></div>
                            </div>
                        </div>
                        <asp:HiddenField ID="hfFurnisher" runat="server" />
                    </div>
                </ContentTemplate>
            </asp:TabPanel>
            <asp:TabPanel runat="server" HeaderText="Pesquisar Fornecedor" ID="tbInsert">
                <HeaderTemplate>Pesquisar Fornecedor</HeaderTemplate>
                <ContentTemplate>
                    <div class="linha">
                        <div class="texto">
                            <div class="control-group">
                                <asp:Label ID="Label2" runat="server" Text="Escola"></asp:Label><div class="controls">
                                    <asp:DropDownList ID="ddlSchooll" CssClass="textbox_search validate[required]" runat="server" Width="365px" Style="margin-left: 1px" AutoPostBack="True"></asp:DropDownList>

                                </div>
                            </div>
                        </div>
                        <div class="field_button">
                            <div class="control-group">
                                <asp:Label ID="Label3" runat="server" Text="Nome"></asp:Label><div class="controls">
                                    <asp:TextBox ID="txtNameSearch" CssClass="textbox_search validate[required]" runat="server" Width="300px"></asp:TextBox>
                                </div>
                            </div>
                        </div>
                        <div class="texto">
                            <div class="control-group">
                                <div class="controls">
                                    <asp:ImageButton ID="btnList" runat="server" ImageUrl="~/Images/Pesquisa_dep.ico" CssClass="btnserchFur furnisher_" OnClick="btnList_Click" ToolTip="Pesquisar" /></div>
                            </div>
                        </div>
                    </div>
                    <br />
                    <br />
                    <div>
                        <asp:GridView ID="gvFurnisher" runat="server" Width="100%" CssClass="GridViewUser" CellPadding="4" AutoGenerateColumns="False" GridLines="None" ForeColor="#333333" OnRowDeleting="gvFurnisher_RowDeleting" OnRowUpdating="gvFurnisher_RowUpdating">
                            <AlternatingRowStyle CssClass="GridAlternativeUser" BackColor="White" />
                            <Columns>
                                <asp:BoundField DataField="FurnisherID" HeaderText="ID Fornecedor" />
                                <asp:BoundField DataField="Name" HeaderText="Nome" />
                                <asp:ButtonField ButtonType="Image" CommandName="Update" ImageUrl="~/images/edit_.png">
                                    <FooterStyle Width="50px" />
                                    <HeaderStyle Width="50px" />
                                    <ItemStyle Width="50px" />
                                </asp:ButtonField>
                                <asp:ButtonField ButtonType="Image" CommandName="Delete" ImageUrl="~/images/Grids_Deletes.png" />

                            </Columns>
                            <EditRowStyle BackColor="#2461BF" />
                            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#EFF3FB" />
                            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#F5F7FB" />
                            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                            <SortedDescendingCellStyle BackColor="#E9EBEF" />
                            <SortedDescendingHeaderStyle BackColor="#4870BE" />
                        </asp:GridView>
                    </div>
                    <br />
                    <asp:Label ID="lbMensagem" runat="server"></asp:Label>
                </ContentTemplate>
            </asp:TabPanel>
        </asp:TabContainer>
    </ContentTemplate>
</asp:UpdatePanel>
<%--  </div>--%>
</asp:Content>

I would like the following Buttons

<div class="buttons">
    <asp:ImageButton ID="btnNew" runat="server" ImageUrl="~/Images/New_6.png" ToolTip="Novo Fornecedor" OnClick="btnNew_Click" />
    <asp:ImageButton ID="btnDelete" runat="server" ImageUrl="~/Images/delete_new.png" ToolTip="Excluir Fornecedor" />
    <asp:ImageButton ID="btnSave" runat="server" ImageUrl="~/Images/save_all.ico" OnClick="btnSave_Click" OnClientClick=" return validate()" ToolTip="Salvar Fornecedor" />
</div>

were enabled only for Tabpanel

<asp:TabPanel runat="server" HeaderText="Cadastrar Fornecedor" ID="tbSearch">

and disable for Tabpanel

<asp:TabPanel runat="server" HeaderText="Pesquisar Fornecedor" ID="tbInsert">

I tried the code below but the Buttons were inside the wrong tabpanel:

<asp:button id="btn" runat="server" OnClientClick="this.disabled=true;"

2 answers

2

Can be rescued via javascript which tab was chosen and also with javascript give a disableb in those buttons. Also use jQuery.

Javascript

<script type="text/javascript">            
    function ActiveTab(sender, e) {
        if (sender._tabs[0]._active) { 
            $("#<%=btnNew.ClientID%>").removeAttr("disabled");
            $("#<%=btnDelete.ClientID%>").removeAttr("disabled");
            $("#<%=btnSave.ClientID%>").removeAttr("disabled");
            //$(".buttons").fadeIn();
        } else {
            if (sender._tabs[1]._active) { 
                $("#<%=btnNew.ClientID%>").attr("disabled", "disabled");
                $("#<%=btnDelete.ClientID%>").attr("disabled", "disabled");
                $("#<%=btnSave.ClientID%>").attr("disabled", "disabled");
                //$(".buttons").fadeOut();                        
            }
        }
    }
    var active = '<%=TabFurnisher.ActiveTabIndex%>';
    $(document).ready(function () {
        if (active == '1') {
            $("#<%=btnNew.ClientID%>").attr("disabled", "disabled");
            $("#<%=btnDelete.ClientID%>").attr("disabled", "disabled");
            $("#<%=btnSave.ClientID%>").attr("disabled", "disabled");
        }                
    });
</script>

Tabpanel

In the Tabpanel (TabFurnisher) was added the OnClientActiveTabChanged="ActiveTab", whereas ActiveTab is the function of javascript.

<asp:TabContainer ID="TabFurnisher" runat="server" TabIndex="0" Width="100%" ActiveTabIndex="1" OnClientActiveTabChanged="ActiveTab">
    <asp:TabPanel runat="server" HeaderText="Cadastrar Fornecedor" ID="tbSearch">
        <HeaderTemplate>Cadastrar Fornecedor</HeaderTemplate>
        <ContentTemplate>
            <div class="linha">
                <div class="tab_tr">
                    <div class="fields_credit">
                        <div class="control-group">
                            <asp:Label ID="Label1" runat="server" Text="Escola"></asp:Label><div class="controls">
                                <asp:DropDownList ID="ddlSchool" CssClass="textbox_search validate[required]" runat="server" Width="365px" Style="margin-left: 1px" AutoPostBack="True"></asp:DropDownList>
                            </div>

                        </div>
                    </div>
                    <div class="texto">
                        <div class="control-group">
                            <asp:Label ID="lblName" runat="server" Text="Name"></asp:Label><div class="controls">
                                <asp:TextBox ID="txtName" runat="server" CssClass="textbox_search validate[required]"></asp:TextBox>
                            </div>
                        </div>
                    </div>
                </div>
                <br />
                <br />
                <br />
                <div class="fieldssd">
                    <div class="control-group">
                        <asp:Label ID="lblDescricao" runat="server" Text="Descrição"></asp:Label><div class="controls">
                            <asp:TextBox runat="server" CssClass="textbox_search validate[required]" Height="40px" Width="500px" ID="txtDesciption" TextMode="MultiLine"></asp:TextBox>
                        </div>
                    </div>
                </div>
                <asp:HiddenField ID="hfFurnisher" runat="server" />
            </div>
        </ContentTemplate>
    </asp:TabPanel>
    <asp:TabPanel runat="server" HeaderText="Pesquisar Fornecedor" ID="tbInsert">
        <HeaderTemplate>Pesquisar Fornecedor</HeaderTemplate>
        <ContentTemplate>
            <div class="linha">
                <div class="texto">
                    <div class="control-group">
                        <asp:Label ID="Label2" runat="server" Text="Escola"></asp:Label><div class="controls">
                            <asp:DropDownList ID="ddlSchooll" CssClass="textbox_search validate[required]" runat="server" Width="365px" Style="margin-left: 1px" AutoPostBack="True"></asp:DropDownList>

                        </div>
                    </div>
                </div>
                <div class="field_button">
                    <div class="control-group">
                        <asp:Label ID="Label3" runat="server" Text="Nome"></asp:Label><div class="controls">
                            <asp:TextBox ID="txtNameSearch" CssClass="textbox_search validate[required]" runat="server" Width="300px"></asp:TextBox>
                        </div>
                    </div>
                </div>
                <div class="texto">
                    <div class="control-group">
                        <div class="controls">
                            <asp:ImageButton ID="btnList" runat="server" ImageUrl="~/Images/6.png" CssClass="btnserchFur furnisher_" OnClick="btnList_Click" ToolTip="Pesquisar" />
                        </div>
                    </div>
                </div>
            </div>
            <br />
            <br />
            <div>
                <asp:GridView ID="gvFurnisher" runat="server" Width="100%" CssClass="GridViewUser" CellPadding="4" AutoGenerateColumns="False" GridLines="None" ForeColor="#333333" OnRowDeleting="gvFurnisher_RowDeleting" OnRowUpdating="gvFurnisher_RowUpdating">
                    <AlternatingRowStyle CssClass="GridAlternativeUser" BackColor="White" />
                    <Columns>
                        <asp:BoundField DataField="FurnisherID" HeaderText="ID Fornecedor" />
                        <asp:BoundField DataField="Name" HeaderText="Nome" />
                        <asp:ButtonField ButtonType="Image" CommandName="Update" ImageUrl="~/images/edit_.png">
                            <FooterStyle Width="50px" />
                            <HeaderStyle Width="50px" />
                            <ItemStyle Width="50px" />
                        </asp:ButtonField>
                        <asp:ButtonField ButtonType="Image" CommandName="Delete" ImageUrl="~/images/Grids_Deletes.png" />

                    </Columns>
                    <EditRowStyle BackColor="#2461BF" />
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#EFF3FB" />
                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                    <SortedAscendingCellStyle BackColor="#F5F7FB" />
                    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                    <SortedDescendingCellStyle BackColor="#E9EBEF" />
                    <SortedDescendingHeaderStyle BackColor="#4870BE" />
                </asp:GridView>
            </div>
            <br />
            <asp:Label ID="lbMensagem" runat="server"></asp:Label>
        </ContentTemplate>
    </asp:TabPanel>
</asp:TabContainer>

References:

1

You could do this in code Behind?

on Tab1_changed_{

btnNew.enabled = true;
btnDelete.enabled = true;

}
on Tab2_changed_{

btnNew.enabled = false;
btnDelete.enabled = false;

}

something like, put an event on the tab when selecting

Browser other questions tagged

You are not signed in. Login or sign up in order to post.