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

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

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;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745601652a4635435.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信