В соответствии с моими предыдущими question, я хочу получить значение скрытого поля ввода из дочерней страницы codebehind.Доступ к значению скрытого поля на Masterpage из codebehind
Я пробовал HtmlInputHidden hdnID = (HtmlInputHidden)Page.Master.FindControl("ctl00_hdnField");
, но получил «нулевое» значение.
Отрывок из Masterpage является:
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="TitleContent" runat="server"></asp:ContentPlaceHolder>
<asp:Literal ID="Literal2" runat="server" Text=" : Logistics Management" />
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="~/css/styles.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="ScriptCssContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
......
......
......
<div id="container">
....
....
....
<div id="content" style="z-index:0;">
<asp:HiddenField ID="hdnField" runat="server" Value=""/>
....
....
....
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
</form>
На моей странице ASPX ребенка, у меня есть этот Javascript блок:
window.onload = function() {
var newDate = new Date();
var hidField = document.getElementById("ctl00_hdnField");
if (hidField != null)
hidField.value = newDate.toLocaleString();
}
Когда я "Add Watch" в
document.getElementById("ctl00_hdnField")
Значение правильное.
Вопрос: Как получить доступ к значению внутри hdnField control, from codebehind?
Вы пытаетесь найти элемент управления с помощью codebehind главной страницы или кодовой записи дочерней страницы? –
Код дочерней страницы – Csharp
Просто создайте свойство readonly с именем 'Master()' на своей дочерней странице, которое возвращает экземпляр главной страницы и ссылается на его дочернюю страницу, например 'Master.hdnField' –