I can't set the value of a hidden field with jquery in asp .net.
My hidden field is declared like this:
<asp:HiddenField runat="server" ID="hdnSelectedTicket" />
And this is how I set the value:
alert(ticketID);
$('#<%=hdnSelectedTicket.ClientID %>').val(ticketID);
alert($('#<%=hdnSelectedTicket.ClientID %>').val());
Both alerts show the right value but when I fetch it at the server it is empty.
#1 jQuery Code to set hidden field value by IDval(); // this gives textbox value $("#myInputHidden"). val(getTxtValue); // this will set hidden field value alert(getValue); Above jQuery code will take textbox value into the variable getTxtValue and using . val() set its value to our hidden field.
Set ClientIDMode="Static"
and then you can use $('#hdnSelectedTicket').val(ticketID);
to set the value in asp hidden field
like
asp:HiddenField ID="hdnSelectedTicket" runat="server" ClientIDMode="Static"
and
$('#hdnSelectedTicket').val(ticketID);
It turns out that I was putting the hidden field inside a div that was used as a model for jquery dialog. When I removed the hidden field from the div and place it somewhere else it worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With