我正在尝试在JavaScript的部分发回后在主页上的用户控件中更新标签。我遇到的问题实际上是访问控件。
主页上的用户控制看起来像这样:
<uc:Header runat="server" ID="Header1" ClientIDMode="Static" />
用户控件的HTML看起来像这样:
<asp:Panel ID="pnlHeader" runat="server" CssClass="page-head">
<h2>
<asp:Label ID="lblTitle" runat="server" Text="Title"></asp:Label></h2>
在我的JavaScript中,我使用以下
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(updateHeader);
function updateHeader() {
alert(document.getElementById('<%=(Master.FindControl("Header1")).ClientID %>'));
}
header1回来null。任何帮助都将不胜感激!
您需要第二次使用FindControl来定位用户控件内的标签。
<%= Master.FindControl("Header1").FindControl("lblTitle").ClientID %>