问题描述
我有一个隐藏字段在我的形式,我设置了服务器上的隐藏字段的值,并试图从JavaScript访问这个值,
I have a hidden field in my form, I'm setting the hidden field's value on the server and trying to access this value from javascript,
我得到的错误:无法获得属性价值的价值:对象为null或undefined
I get the error: Unable to get value of the property 'value': object is null or undefined
如果我查看隐藏字段的值设置为源和隐藏字段的ID是一样的我打电话的ID。
If I view the source the hidden field value is set and the ID of the hidden field is the same as the ID I'm calling.
ASPX
var v = document.getElementById('hxValue').value;
<asp:HiddenField ID="hxValue" runat="server"/>
VB
hxValue.Value = "Value1"
我记得以前这样做的,它应该是比较简单的,但是由于某些原因,我没有得到它的权利。
I recall doing this before and it should be relatively simple but for some reason, i'm not getting it right.
推荐答案
您code会工作。对于简单的形式,只需要添加
Your code will work. For simple forms, just add
<asp:HiddenField ClientIDMode="static" ID="hxValue" runat="server"/>
或
您需要使用才能找到客户ID
you need to find the client id using
'<%=hxValue.ClientID%>'
这篇关于访问在JavaScript的隐藏字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!