如何在客户端触发服务器端控件的事情?
以下的代码是要实现:通过点击Button1控件,通过客户端的javascript激发Button2控件的click事件,但不成功。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function AA()
{
document.all("Button2").click();
return confirm("aa");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" OnClientClick="return AA();"/>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button2" /></div>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "AA");
}
protected void Button2_Click(object sender, EventArgs e)
{
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this.Button2, this.Button1.GetType(), "ajs", "alert('不正确!');", true);
}
protected void Button1_Click(object sender, EventArgs e)
{
}