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

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

posted on   秋天  阅读(3711)  评论(0编辑  收藏  举报

编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构

导航

< 2008年2月 >
27 28 29 30 31 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示