Button,LinkButton...弹出新窗口及关闭

时间:2022-08-18 23:42:27

1.Button
html

<asp:Button ID="Button1" runat="server" Text="Response弹出新窗口" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="关闭" />

<input type="button" value="关闭" onclick="window.close()"/>

.cs
在Page_Load里加
    Button1.Attributes.Add("onclick", "this.form.target='_blank'");

protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Default.aspx");//此弹出的窗口为新窗口.
    }
protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.opener=null;window.close();</script>");
    }
2.LinkButton
.cs

LinkButton1.Attributes.Add("OnClientClick", "window.open('XXXaspx','_blank')");
或是用脚本.//UpdatePanl1这个是这个linkbutton放在UpdatePanl1里时用的.
ScriptManager.RegisterClientScriptBlock(UpdatePanl1, UpdatePanl1.GetType(), "", "<script>window.open('xxx.aspx')</script>", false);
ImageButton也一样.
本文来自: ASP.NET学习门户(http://www.aspx1.com) 详细出处参考:http://i.aspx1.com/showtopic-796.htm