How to set asp.net hidden field in JavaScript and access the value in C# code behind - Stack Overflow

admin2025-04-26  1

I'm trying to set hidden field value in JS which I think works fine with this approach:

  <asp:HiddenField ID="hfLatSW" runat="server" />

   var latSW = bounds.getSouthWest().lat();
   $('#<%=hfLatSW.ClientID %>').value = latSW;

I am trying to access the value on asp button click in code behind gives me null value. What might be happening in the postback and why am I not able to access the value set by JavaScript?

I'm trying to set hidden field value in JS which I think works fine with this approach:

  <asp:HiddenField ID="hfLatSW" runat="server" />

   var latSW = bounds.getSouthWest().lat();
   $('#<%=hfLatSW.ClientID %>').value = latSW;

I am trying to access the value on asp button click in code behind gives me null value. What might be happening in the postback and why am I not able to access the value set by JavaScript?

Share Improve this question edited Nov 10, 2021 at 21:18 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Apr 6, 2014 at 18:51 LazialeLaziale 8,24548 gold badges155 silver badges271 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

.value isn't a jQuery property. Use .val():

$('#<%=hfLatSW.ClientID %>').val(latSW);

Or without jQuery:

document.getElementById('<%=hfLatSW.ClientID %>').value = latSW;
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745601653a309342.html

最新回复(0)