Jquery Selector in a User Control, inside a gridview

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 when 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 the following and it did not 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;
 }
    
asked by anonymous 07.05.2018 / 22:21

1 answer

0

I have not yet worked with JQuery in Asp.Net, but the syntax for getting the value of the items by the id seems correct.

But have you ever tested ('#idDoElemento.ClientID').val(); instead of ('#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();
 }
    
07.05.2018 / 22:46