![](/img/trans.png)
[英]how to set asp.net hidden field in javascript and access the value in c# code behind
[英]How to access hidden field value from java script code(Client side) in asp.net c#
我在.aspx 頁面(ui) 中定義了隱藏字段
<asp:HiddenField ID ="hdnExport" runat="server" />
在以下代碼(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");
});
});
然后訪問 aspx.cs 代碼中的隱藏字段值如下所示,
string exportValue = Convert.ToString(hdnExport.Value);
string exp = hdnExport.Value.ToString();
var val = this.hdnExport.Value;
string latitudeValue = Request.Form[hdnExport.Value];
嘗試了不同的方法。 但我沒有從隱藏字段中獲得價值。 如何解決這個問題
默認情況下,呈現的id
將不同於 C# ( hdnExport
) 中指定的ID
。 因此,( #hdnExport
) 可能是無效的選擇器,因此未設置任何值。
嘗試在HiddenField
上設置ClientIDMode="Static"
:
<asp:HiddenField ID ="hdnExport" ClientIDMode="Static" runat="server" />
這將確保隱藏字段以id
作為ID
呈現,這將使#hdnExport
有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.