[英]How to access hidden field value from java script code(Client side) in asp.net c#
I have defined hidden field in.aspx page(ui)我在.aspx 页面(ui) 中定义了隐藏字段
<asp:HiddenField ID ="hdnExport" runat="server" />
Set the value in the following code (java script)在以下代码(java 脚本)中设置值
$(document).ready(function () {
$("#btn_FinalConfirmOK").on("click", function (event) {
alert("clicked");
//document.getElementById("hdnExport").value = "yes";
$('#hdnExport').val("yes");
alert($('#hdnExport').val());
document.getElementById('hdnExport').value = "yes";
//alert("yes");
});
});
Then accessing hidden field value in aspx.cs code is given below,然后访问 aspx.cs 代码中的隐藏字段值如下所示,
string exportValue = Convert.ToString(hdnExport.Value);
string exp = hdnExport.Value.ToString();
var val = this.hdnExport.Value;
string latitudeValue = Request.Form[hdnExport.Value];
Tried with different ways.尝试了不同的方法。 but i didn't get value from hidden field.
但我没有从隐藏字段中获得价值。 how to solve this issue
如何解决这个问题
By default, the rendered id
will differ from the ID
specified within C# ( hdnExport
).默认情况下,呈现的
id
将不同于 C# ( hdnExport
) 中指定的ID
。 Therefore, ( #hdnExport
) is likely an invalid selector thus no value is set.因此,(
#hdnExport
) 可能是无效的选择器,因此未设置任何值。
Try setting ClientIDMode="Static"
on the HiddenField
:尝试在
HiddenField
上设置ClientIDMode="Static"
:
<asp:HiddenField ID ="hdnExport" ClientIDMode="Static" runat="server" />
This will ensure the hidden field is rendered with id
as ID
which would make #hdnExport
valid.这将确保隐藏字段以
id
作为ID
呈现,这将使#hdnExport
有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.