我正在尝试使用JavaScript检索服务器控件。为了测试目的,我从页面加载事件中调用JavaScript函数。
protected void Page_Load(object sender, EventArgs e){
ClientScript.RegisterClientScriptBlock(GetType(), "js", "confirmCallBack();", true);
}
我的JavaScript函数是:
function confirmCallBack() {
var a = document.getElementById('<%= Page.Master.FindControl("PlaceHolderContent").FindControl("Button1").ClientID %>');
var b = document.getElementById('<%=Button1.ClientID%>');
}
我的问题是a和b都返回null。即使在查看页面源代码时,正确的ClientID也已经返回。
我应该补充的是,我正在使用母版页。
有什么想法吗?