最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin6PV0评论

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;
Post a comment

comment list (0)

  1. No comments so far