获取一个asp的价值:使用jQuery HiddenField [英] Get the Value of an asp:HiddenField using jQuery
问题描述
我有两页。从第一页,我打开与保存客户名的该值的查询字符串一个模式。然后,我用它来设置打开该模式一hiddenfield。
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.
我试着让使用值:
var hv = $('hidClientField').val();`
不过,这似乎并没有工作。
But this doesn't seem to work.
这是我的隐藏字段:
<asp:HiddenField ID="hidClientName" runat="server" />`
我将它设置在code落后于像这样在Page_Load:
I set it in the code behind on the Page_Load like this:
hidClientName.Value = Request.QueryString["Client_Name"] ?? "";`
任何想法将大大AP preciated。
Any ideas will be much appreciated.
推荐答案
尝试以下任何
-
如果ASP.Net控制和JavaScript都是同一个页面上,然后用
If ASP.Net control and javascript both are on same page, then use
var hv = $("#"+ '<%= hidClientField.ClientID %>').val();
如果您想从一些JS文件访问控制,那么
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();
您可以使用类名选择器来实现相同的。查看<一个href=\"http://stackoverflow.com/questions/641280/reference-asp-net-control-by-id-in-javascript\">this类似的问题。
在asp.net,控制id是错位的。因此您code是行不通的。
In asp.net, controls id is mangled. Because of this your code is not working.
希望这对你的作品。
这篇关于获取一个asp的价值:使用jQuery HiddenField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!