I have two pages. From the first page, I open a modal with a querystring that holds that value of a client name. I then use this to set a hiddenfield on the modal that opened.
I need a TextBox on the new modal to display the value that has been sent through from the first screen.
I've tried getting the value using:
var hv = $('hidClientField').val();`
But this doesn't seem to work.
This is my hidden field:
<asp:HiddenField ID="hidClientName" runat="server" />`
I set it in the code behind on the Page_Load like this:
hidClientName.Value = Request.QueryString["Client_Name"] ?? "";`
Any ideas will be much appreciated.
#1 jQuery Code To Get hidden field value by IDvar getValue= $("#myInputHidden"). val(); alert(getValue); Here we select the input hidden field by the ID, i.e myInputHidden, and with the jQuery . val() method we get the value of it.
To begin with using jQuery with ASP.NET, first download the latest version the jQuery library from jQuery website and unzip or copy the file in your project or Visual studio solution. Microsoft Visual studio 2010 and 2012 include jQuery by default and provide intellisense to use jQuery.
Try any of the following
If ASP.Net control and javascript both are on same page, then use
var hv = $("#"+ '<%= hidClientField.ClientID %>').val();
If you want to access the control from some JS file, then
// 'id$' will cause jQuery to search control whose ID ends with 'hidClientField' var hv = $('input[id$=hidClientField]').val();
You can use class name selector to achieve same. Check out this similar question.
In asp.net, controls id is mangled. Because of this your code is not working.
Hope this works for you.
You forgot the #
in your selector to select by ID:
var hv = $('#hidClientField').val();
Although asp.net generates ID based on the naming containers so you might end up with an ID like ctl1$hidClientField
. You can then use the "attribute ends with" selector:
var hv = $('input[id$=hidClientField]').val();
Check the documentation about jQuery selectors
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