使用Reoe.Redirect打开新窗口的方法_.NET概论及软件使用_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

使用Reoe.Redirect打开新窗口的方法

作者:黑客防线网安ASP维护基地 来源:黑客防线网安ASP维护基地 浏览次数:0

本篇关键词:方法窗口打开使用
黑客防线网安网讯:    方法一:  protected void Page_Load(object sender, EventArgs e)  {  form1.Target = "_blank";  }  protected void Button1_Click(object sender, EventArgs e)  {  R...
    方法一:
  protected void Page_Load(object sender, EventArgs e)
  {
  form1.Target = "_blank";
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  Response.Redirect("http://dotnet.aspx.cc");
  }
  办法二:采用客户端脚本的方法设置 target 属性代码如下:
  复制  保存
  protected void Page_Load(object sender, EventArgs e)
  {
  Button1.Attributes.Add("onclick", "this.form.target='_newName'");
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  Response.Redirect("http://dotnet.aspx.cc");
  }
  方法三
  protected void Page_Load(object sender, EventArgs e)
  {
  string WindowName = "win" + System.DateTime.Now.Ticks.ToString();
  Page.RegisterOnSubmitStatement("js", "window.open('','" + WindowName + "','width=600,height=200')");
  form1.Target = WindowName;
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  Response.Redirect("http://dotnet.aspx.cc");
  }
  方法4:
  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 = @"<script>window.open(""{0}"", ""{1}"", ""{2}"");</script>"; }
  else
  {
  script = @"<script>window.open(""{0}"", ""{1}"");</script>";
  }
  script = String.Format(script, url, target, windowFeatures);
  //ScriptManager.RegisterStartupScript(page, typeof(Page), "Redirect", script, true);
  page.RegisterStartupScript("ddd", script);
  }
  }
  }
  调用:
  ResponseHelper.Redirect("popup.aspx", "_blank", "menubar=0,width=100,height=100");
    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-14425-1.html
网站维护教程更新时间:2012-03-30 05:51:04  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer