Jquery Selector in a User Control, within a gridview

Asked

Viewed 36 times

1

Good afternoon, I have the following code:

<asp:GridView runat="server" Style="border: 0px !important;" ID="gdvDadosHistoricoMedico" OnRowDataBound="gdvDadosHistoricoMedico_RowDataBound"
                            AutoGenerateColumns="false" ShowHeader="false" Visible="false">
                            <AlternatingRowStyle />
                            <RowStyle />
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <local:UCHistoricoAtendimentoMedico runat="server" ID="UCHistoricosAtendimentoMedicos" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>

Inside the user control I have fields that I would like to get the value with jquery by clicking a button:

<div class="col-sm-4">
                                            <governa:GVNCalendar ID="cldDataMedicamento" DiasLimiteFinal="7" Tipo="Data" runat="server" Requerido="True" />
                                        </div>
                                        <div class="col-sm-1">
                                            <asp:Label ID="lblCMHora" Text="Hora"  runat="server"></asp:Label>
                                        </div>
                                        <div class="col-sm-4">
                                            <governa:GVNCalendar ID="cldHoraMedicamento" Tipo="Hora" ClientIDMode="AutoID" runat="server" Requerido="True" />
                                        </div>
                                        <asp:HiddenField ID="hdfCodPrescricaoObservacao" runat="server" />
                                        <asp:HiddenField ID="hdfCodUsuarioResponsavel" runat="server" />
                                        <asp:HiddenField ID="hdfNomUsuarioResponsavel" runat="server" />
                                        <div class="col-sm-1">
                                            <button ID="GravarHorario" onclick="AdicionarNaTabela()">Clique</button>
                                        </div>

What would be the javascript/jquery code to get the value? I tried it this way and it didn’t work:

function AdicionarNaTabela() {    
    var cldDataMedicamento = $('#<%=cldDataMedicamento.ClientID %>').val;
    var cldHoraMedicamento = $('#<%=cldHoraMedicamento.ClientID %>').val;
    var hdfCodPrescricaoObservacao = $('#<%hdfCodPrescricaoObservacao.ClientID %>').val;
    var codProfissional = $('#<%=hdfCodUsuarioResponsavel.ClientID %>').val;
    var nomProfissional = $('#<%=hdfNomUsuarioResponsavel.ClientID %>').val;
 }

1 answer

0


I haven’t worked with Jquery on Asp.Net yet, but the syntax to get the value of the items by id seems correct.

But you’ve already tested ('#idDoElemento.ClientID').val(); rather than ('#idDoElemento.ClientID').val; ? Since .val() is a method to get the value of the element, test with the parentheses at the end and will probably work.

function AdicionarNaTabela() {    
    var cldDataMedicamento = $('#<%=cldDataMedicamento.ClientID %>').val();
    var cldHoraMedicamento = $('#<%=cldHoraMedicamento.ClientID %>').val();
    var hdfCodPrescricaoObservacao = $('#<%hdfCodPrescricaoObservacao.ClientID %>').val();
    var codProfissional = $('#<%=hdfCodUsuarioResponsavel.ClientID %>').val();
    var nomProfissional = $('#<%=hdfNomUsuarioResponsavel.ClientID %>').val();
 }
  • Actually, this was one of the errors of my code, but now I have another problem, jquery always recovers the value of the last User Control of grid view. Any hint?

  • @Guilhermecampos glad the answer was useful, please mark it as useful, as an answer (since she solved her question "What would be the javascript/jquery code to get the value?") and close. So the question of the initial scope will not be open waiting for answers. As for this other question, which appeared later (as it is in your comment "...but now I have another problem..."), you should detail better in another question so that all users (including myself) can understand better and help you.

Browser other questions tagged

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