简体   繁体   中英

Javascript Object required error when calling value of hidden field

Code: Html:

<input type="hidden" id="lblHierarchyType" value="" runat="server" />

C# Codebehind:

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;
        }

The code errors out (Microsoft JScript runtime error: Object required) when it hits the assignment of lblHierarachy.value to var hierarchy.

Thanks

The ID that ASP.NET will generate will not be "lblHierarchyType" so better to change it by its ClientID

 var hierarchyType = document.
                   getElementById("<%= lblHierarchyType.ClientID%>").value;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM