服务器控件,调用隐藏的服务器按钮的点击事件
.cs代码:
protected void Button2_Click(object sender, EventArgs e) { string js="window.document.getElementById('Upbtn').click();"; ScriptManager.RegisterStartupScript(this, Page.GetType(), "", string.Format(js, ""), true);
TextBox2.Text = "点击了隐藏的按钮"; } protected void Upbtn_Click1(object sender, EventArgs e) { TextBox3.Text = "我是隐藏按钮,被调用了!"; }
|
aspx页面:
button放在DIV中,div的style设置为:<div style="display:none">
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button1" /> <br />
</div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <br /> <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button2" /> <br /> <asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>
<div style="display:none"> <asp:Button ID="Upbtn" runat="server" Text="Button3" onclick="Upbtn_Click1" /> </div>
<br /> <br /> <br /> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</form> </body> </html>
|
效果
启动后页面效果
点击Button2后的效果
|