admin管理员组

文章数量:1023782

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;

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;

本文标签: How to set aspnet hidden field in JavaScript and access the value in C code behindStack Overflow