代码: HTML:
<input type="hidden" id="lblHierarchyType" value="" runat="server" />
C# 代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
if (lblHierarchyType.Value == "")
{
lblHierarchyType.Value = "AOR";
}
if (!Page.IsPostBack)
{
txtUserID.Focus();
FillGroupsList();
FillOrgTree();
ClearErrorMsgs();
}
}
Javascript:
function populateSelectedNode(node) {
debugger
var selectedOrg = node.getValue();
var hierarchyType = document.getElementById("lblHierarchyType").value;
}
代码在将 lblHierarchy.value 分配给 var 层次结构时出现错误(Microsoft JScript 运行时错误:需要对象)。
谢谢
最佳答案
ASP.NET 将生成的 ID 不会是“lblHierarchyType”,因此最好通过其 ClientID 更改它
var hierarchyType = document.
getElementById("<%= lblHierarchyType.ClientID%>").value;
关于c# - 调用隐藏字段的值时Javascript对象需要错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10109951/