方法一:
protected void Page_Load(object sender, EventArgs e)
{
form1.Target = "_blank";
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("http://www..17aspx.ccom");
}
办法二:采用客户端脚本的方法设置 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://www..17aspx.ccom");
}
方法三
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://www..17aspx.ccom");
}
方法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");
方法5:
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "window.open(''a.aspx'')");
}
a.aspx就是你要打开那个页面的名称
这个是注册客户端,不用在服务器端Button1按钮的Click事件下写跳转的东西。
|