none
eventos click dos botoes e imagebutton não funcionam RRS feed

  • Pergunta

  • bom dia pessoal tenho uma pagina onde tenho um repeater que populo com dados da empresa atraves de um datatable ,ate ai tudo bem esta funcionando o problema é que qualquer botão da pagina não funciona o evento click se eu deixar o panel na pagina eu uso o panel no modalextender.

    um exemplo no meu codigo eu programei somente este button:abaixo e o evento click não é acionado caso o panel fique na pagina.

                        <asp:ImageButton ID="btnexcel" BorderColor="#000" Width="3%" runat="server" ImageUrl="~/images/Menubotoes/excel1.png"
                            OnClick="excel_click" />

    segue meu codigo aspx:

     <div id="Pagina">
            <table cellpadding="1" cellspacing="1" border="1" width="100%" style="border: 0 px solid #000;
                color: Yellow; background-color: #316BA5">
                <tr style="text-align: right">
                    <td colspan="2">
                        <b>Exportar Dados</b>
                    </td>
                </tr>
                <tr style="text-align: right">
                    <td>
                        <asp:ImageButton ID="btnexcel" BorderColor="#000" Width="3%" runat="server" ImageUrl="~/images/Menubotoes/excel1.png"
                            OnClick="excel_click" />
                        <asp:ImageButton ID="btncsv" Width="3%" runat="server" ImageUrl="~/images/Menubotoes/csv1.png" />
                        <asp:ImageButton ID="btnword" Width="3%" runat="server" ImageUrl="~/images/Menubotoes/word1.png" />
                        <asp:ImageButton ID="btnpdf" Width="3%" runat="server" ImageUrl="~/images/Menubotoes/adobe1.png" />
                    </td>
                </tr>
            </table>
            <table cellpadding="1" cellspacing="1" border="1" width="100%" style="border: 1px solid #000;
                color: #000">
                <tr style="background-color: #CCC; font-family: Arial; font-size: 18px; text-align: left">
                    <td style="width: 4%">
                        <asp:Button ID="Btnnovo" runat="server" Text="Novo" />
                    </td>
                    <td>
                        <asp:Button ID="btnimprimir" runat="server" Text="Imprimir" />
                    </td>
                </tr>
            </table>
            <br />
            <asp:Repeater runat="server" ID="grddados">
                <HeaderTemplate>
                    <table cellpadding="0" cellspacing="1" border="1" width="100%" style="border: 1px solid #000">
                        <tr style="background-color: gray; color: #FFF; font-family: Arial; font-size: 17px;
                            text-align: center">
                            <td colspan="11">
                                Relação de Empresas Cadastradas
                            </td>
                        </tr>
                        <tr style="background-color: #CCC; color: #000; font-family: Arial; font-size: 13px;">
                            <td>
                                <b>Código</b>
                            </td>
                            <td>
                                <b>Ramo Atividade</b>
                            </td>
                            <td>
                                <b>Nome Empresa</b>
                            </td>
                            <td>
                                <b>Razão Social</b>
                            </td>
                            <td>
                                <b>Cnpj</b>
                            </td>
                            <td>
                                <b>Data da Fundação</b>
                            </td>
                            <td colspan="5">
                                <b>Ações</b>
                            </td>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr class="RowStyle">
                        <td>
                            <%#Eval("chave") %>
                        </td>
                        <td>
                            <%#Eval("RAMO") %>
                        </td>
                        <td>
                            <%#Eval("NOME") %>
                        </td>
                        <td>
                            <%#Eval("RAZAOSOCIAL") %>
                        </td>
                        <td>
                            <%#Eval("CNPJ") %>
                        </td>
                        <td>
                            <%#Eval("FUNDACAO") %>
                        </td>
                        <td>
                            <asp:ImageButton runat="server" ImageUrl="~/images/Menubotoes/button_edit.gif" />
                        </td>
                        <td>
                            <asp:ImageButton ID="ImageButton7" runat="server" ImageUrl="~/images/Menubotoes/button_delete.gif" />
                        </td>
                        <td>
                            <asp:ImageButton ID="ImageButton8" runat="server" ImageUrl="~/images/Menubotoes/button_print.gif" />
                        </td>
                    </tr>
                </ItemTemplate>
                <AlternatingItemTemplate>
                    <tr class="AlternatingRowStyle">
                        <td>
                            <%#Eval("chave")%>
                        </td>
                        <td>
                            <%#Eval("RAMO") %>
                        </td>
                        <td>
                            <%#Eval("NOME") %>
                        </td>
                        <td>
                            <%#Eval("RAZAOSOCIAL") %>
                        </td>
                        <td>
                            <%#Eval("CNPJ") %>
                        </td>
                        <td>
                            <%#Eval("FUNDACAO") %>
                        </td>
                        <td>
                            <asp:ImageButton ID="ImageButton9" runat="server" ImageUrl="~/images/Menubotoes/button_edit.gif" />
                        </td>
                        <td>
                            <asp:ImageButton ID="ImageButton7" runat="server" ImageUrl="~/images/Menubotoes/button_delete.gif" />
                        </td>
                        <td>
                            <asp:ImageButton ID="ImageButton8" runat="server" ImageUrl="~/images/Menubotoes/button_print.gif" />
                        </td>
                    </tr>
                </AlternatingItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>
            <p style="background-color: gray; width: 100%; border: 1px solid #000; height: 4%;
                font-size: 13px; color: #000; text-align: center;">
                <asp:ImageButton runat="server" ID="btnant" ImageUrl="~/images/Menubotoes/arrow_left.png"
                    OnClick="btnant_click" />
                <b>
                    <asp:Label runat="server" ID="label1"></asp:Label></b> <b>
                        <asp:Label runat="server" ID="label2"></asp:Label></b>
                <asp:ImageButton runat="server" ID="ImageButton1" ImageUrl="~/images/Menubotoes/arrow_right.png"
                    OnClick="btnnext_click" />
            </p>
            <%-- -----------------------------------------------------------------------------------------------%>
            <asp:Panel ID="Panel1" runat="server" Style="display: none;" CssClass="ModalWindow">
                <div class="DivFrame_Paginas">
                    <center>
                        <p style="background-color: #316BA5; color: Yellow; font-size: 14px; text-align: center">
                            CADASTRO DE EMPRESAS
                        </p>
                    </center>
                    <fieldset style="text-align: left; width: 560px; height: 285px; background-color: #FFF;
                        color: #000">
                        <legend style="text-align: left; border: 1px solid #000000; background-color: #CCC;
                            font-size: small;"><span>Cadastrar Dados Empresa</span> </legend>
                        <br />
                        <table cellpadding="1" cellspacing="1" border="0" width="100%" style="background-color: #FFF;
                            color: #000">
                            <tr>
                                <td>
                                    Grupo:
                                </td>
                                <td>
                                    <asp:TextBox ID="txtgrupo" runat="server" Height="18px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Campo Grupo Obrigatorio"
                                        Text="*" ControlToValidate="txtgrupo"></asp:RequiredFieldValidator>
                                    <asp:ValidatorCalloutExtender ID="Validatorcalloutextender5" runat="server" TargetControlID="RequiredFieldValidator1"
                                        Width="270px" PopupPosition="TopLeft">
                                    </asp:ValidatorCalloutExtender>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Matriz:
                                </td>
                                <td>
                                    <asp:CheckBox ID="CheckBox1" runat="server" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Nome:
                                </td>
                                <td>
                                    <asp:TextBox ID="txtnome" runat="server" Width="310px" Height="18px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Campo Nome Obrigatorio"
                                        Text="*" ControlToValidate="txtnome"></asp:RequiredFieldValidator>
                                    <asp:ValidatorCalloutExtender ID="Validatorcalloutextender2" runat="server" TargetControlID="RequiredFieldValidator2"
                                        Width="270px" PopupPosition="TopLeft">
                                    </asp:ValidatorCalloutExtender>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    CNPJ:
                                </td>
                                <td>
                                    <asp:TextBox ID="txtcnpj" runat="server" Height="16px" Width="145px"></asp:TextBox>
                                    <asp:MaskedEditExtender ID="txtcnpj_MaskedEditExtender" runat="server" CultureAMPMPlaceholder=""
                                        CultureCurrencySymbolPlaceholder="" CultureDateFormat="" CultureDatePlaceholder=""
                                        CultureDecimalPlaceholder="" CultureThousandsPlaceholder="" CultureTimePlaceholder=""
                                        Enabled="True" Mask="99,999,999/9999-99" TargetControlID="txtcnpj" MaskType="None">
                                    </asp:MaskedEditExtender>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Campo CNPJ Obrigatorio"
                                        Text="*" ControlToValidate="txtcnpj"></asp:RequiredFieldValidator>
                                    <asp:ValidatorCalloutExtender ID="Validatorcalloutextender1" runat="server" TargetControlID="RequiredFieldValidator3"
                                        Width="270px" PopupPosition="TopLeft">
                                    </asp:ValidatorCalloutExtender>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Razão Social:
                                </td>
                                <td>
                                    <asp:TextBox ID="txtrazao" runat="server" Height="18px" Width="145px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Campo Razão Obrigatorio"
                                        Text="*" ControlToValidate="txtrazao"></asp:RequiredFieldValidator>
                                    <asp:ValidatorCalloutExtender ID="Validatorcalloutextender3" runat="server" TargetControlID="RequiredFieldValidator4"
                                        Width="270px" PopupPosition="TopLeft">
                                    </asp:ValidatorCalloutExtender>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    IE:
                                </td>
                                <td>
                                    <asp:TextBox ID="txtie" runat="server" Height="18px" Width="86px"></asp:TextBox>
                                    <asp:MaskedEditExtender ID="txtie_MaskedEditExtender" runat="server" CultureAMPMPlaceholder=""
                                        CultureCurrencySymbolPlaceholder="" CultureDateFormat="" CultureDatePlaceholder=""
                                        CultureDecimalPlaceholder="" CultureThousandsPlaceholder="" CultureTimePlaceholder=""
                                        Enabled="True" Mask="999/9999999" TargetControlID="txtie" MaskType="Number">
                                    </asp:MaskedEditExtender>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="Campo IE Obrigatorio"
                                        Text="*" ControlToValidate="txtie"></asp:RequiredFieldValidator>
                                    <asp:ValidatorCalloutExtender ID="Validatorcalloutextender4" runat="server" TargetControlID="RequiredFieldValidator5"
                                        Width="270px" PopupPosition="TopLeft">
                                    </asp:ValidatorCalloutExtender>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Data Fundação:
                                </td>
                                <td class="style158">
                                    <asp:TextBox ID="txtdata" runat="server" Height="18px" Width="87px"></asp:TextBox>
                                    <asp:MaskedEditExtender ID="txtdata_MaskedEditExtender" runat="server" CultureAMPMPlaceholder=""
                                        CultureCurrencySymbolPlaceholder="" CultureDateFormat="" CultureDatePlaceholder=""
                                        CultureDecimalPlaceholder="" CultureThousandsPlaceholder="" CultureTimePlaceholder=""
                                        Enabled="True" Mask="99/99/9999" MaskType="Date" TargetControlID="txtdata" UserDateFormat="DayMonthYear">
                                    </asp:MaskedEditExtender>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Ramo&nbsp; Atividade:
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlramo" runat="server" Height="20px" Width="222px">
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" align="left">
                                    <b>
                                        <asp:Label ID="lblresult" runat="server"></asp:Label></b>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" align="left">
                                    <asp:Image runat="server" ImageUrl="~/images/msg-ok.gif" Visible="false" ID="image1" />
                                    <asp:Image ID="Image2" runat="server" ImageUrl="~/images/msg-error.gif" Visible="false" />
                                </td>
                            </tr>
                        </table>
                    </fieldset>
                    <p style="text-align: left;">
                        <asp:Button ID="OkButton" runat="server" Text="Gravar" OnClick="OkButton_click" />
                        <asp:Button ID="CancelButton" runat="server" Text="Cancel" />
                    </p>
                </div>
            </asp:Panel>
        </div>
        <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Btnnovo"
            PopupControlID="Panel1" BackgroundCssClass="modalBackground1" CancelControlID="CancelButton"
            DropShadow="True" PopupDragHandleControlID="Panel1" DynamicServicePath="" Enabled="True">
        </asp:ModalPopupExtender>
        <asp:ToolkitScriptManager EnableScriptGlobalization="true" EnableScriptLocalization="true"
            runat="server">
        </asp:ToolkitScriptManager>


    quinta-feira, 29 de março de 2012 10:30

Todas as Respostas

  • para seu button fucionar ele tem que estar dentro de um updatePanel

    Não esqueça de usar o componente </> na barra para posta seu código. Microsoft MCPD,MCTS,MCC

    quinta-feira, 29 de março de 2012 11:51
    Moderador
  • bleza entendi mas porque usar o updatePanel qual a moral se meus botões estão fora do meu panel1
    quinta-feira, 29 de março de 2012 14:23
  • Boa Tarde,

    Neste caso, utilize o Método ItemCommand do Repeater, cada ação que houver nesses botões, irá disparar esse método. No ItemDataBound do seu repeater vc pode configurar o .CommandName="" e .CommandArgument de cada botão e assim fazer ações necessárias. Segue exemplo:

     protected void SeuRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.DataItem == null) return;
    
                var x = ((SeuObjeto)e.Item.DataItem);
    
                ImageButton btn = e.Item.FindControl("ImageButton7") as ImageButton;
    
    
                btn.CommandName = "Export";
                btn.CommandArgument = "Valro necssário(ex. Id do Item)";
    }
    
            protected void SeuRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
            {
                var Id = Convert.ToInt32(e.CommandArgument);
    
    
                if (e.CommandName == "Export")
                {
                  //Ação necessária 
    }
            }

    Espero ter ajudado

    Abcs

    quinta-feira, 29 de março de 2012 20:19
  • bom dia,os meus imagebuttons não estão dentro do repetidor estão fora ,eu identifiquei o problema mas não entendi o porque,o problema são os <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Campo Nome Obrigatorio"
                                        Text="*" ControlToValidate="txtnome"></asp:RequiredFieldValidator> se eu ativar o showmessage do controle funciona os eventos clicks mas da mensagem programada aqui se não não funciona então retirei estas validações e testei ai funcionou .
    sexta-feira, 30 de março de 2012 10:23