aspx中代码
<script language=javascript >
function clickMe()
{
document.getElementByID( " test " )
}
</script>
母版页中控件为:
<asp:TextBox id = "test" runat = "server"></asp:TextBox>
<asp:Button id = "btnTest" runat = "server"></asp:Button>
aspx.cs中代码
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
//LoadData();
btnTest.Attributes.Add("onclick", "clickMe()");
}
}
当单击button按钮时就会报document.getElementByID( " test " )不存在等的错误,后来经网友提示,原来在母版页中
服务器端控键输出到客户端后它的ID属性值会变,所以只要你看看源文件,然后把那个ID属性值写在
document.getElementByID中就正确.例如客户端为ct100_a_test,这时将 document.getElementByID( " test " )
改为 document.getElementByID( " ct100_a_test," )就不会报错
^_^