2013-10-02 678 views
3

我想在加载自己的同时在新窗口中打开asp.net页面。我试着用下面的代码。但它在同一个窗口中打开,而不是在新窗口中打开。在新窗口中打开asp.net页面

 protected void Page_Load(object sender, EventArgs e) 
    { 
     if (HttpContext.Current.Request.UserAgent != null) 
     { 
      var userAgent = HttpContext.Current.Request.UserAgent.ToLower(); 

      if (userAgent.Contains("iphone;")) 
      { 
       // iPhone 
       Form.Target = "_blank"; 

      } 


     } 
    } 

任何帮助表示赞赏。谢谢 !!

+0

http://stackoverflow.com/questions/16145187/how-to-open-a-page-in-a-new-window-or-tab-from-code-behind –

回答

7

在代码中使用JavaScript背后重定向:

Response.Write("<script>window.open('http://www.google.com.hk/','_blank');</script>"); 

或者使用ScriptManager,你可以传递参数太多:

ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('YourPage.aspx?Param=" + ParamX.ToString() + "');",true); 

或者,如果你有一个按钮,你可以如下使用它:

Button1.OnClientClick="javascript:window.open('YourPage.aspx?Param=" + ParamX.ToString() + "');"; 
0

这就是我所做的,只是试试这个

ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('ViewDetails.aspx','mywindow','menubar=1,resizable=1,width=900,height=600');", true); 
相关问题