您的位置:首页 > 编程语言 > ASP

ASP.NET 后台打开新窗口 并控制窗口参数

2011-09-23 15:14 239 查看
//新窗口类

public static class ResponseHelper

{

public static void Redirect(string url, string target, string windowFeatures)

{

HttpContext context = HttpContext.Current;

if ((String.IsNullOrEmpty(target) || target.Equals("_self", StringComparison.OrdinalIgnoreCase)) && String.IsNullOrEmpty(windowFeatures))

{

context.Response.Redirect(url);

}

else

{

Page page = (Page)context.Handler;

if (page == null)

{

throw new InvalidOperationException("Cannot redirect to new window outside Page context.");

} url = page.ResolveClientUrl(url);

string script;

if (!String.IsNullOrEmpty(windowFeatures))

{

script = @"window.open(""{0}"", ""{1}"", ""{2}"");";

} else

{

script = @"window.open(""{0}"", ""{1}"");";

}

script = String.Format(script, url, target, windowFeatures);

ScriptManager.RegisterStartupScript(page, typeof(Page), "Redirect", script, true);

}

}

}

调用:

Response.Redirect("query_Detail.aspx", "_blank", "menubar=0,width=850,height=590");

效果:





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: