在新窗口打开ASP.NET页面

4
我正在尝试在加载页面时在新窗口中打开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";

            }


        }
    }

非常感谢您的帮助!如有需要,欢迎联系我们。谢谢!


https://dev59.com/nGQo5IYBdhLWcg3wUeCL - Jibran Khan
2个回答

13

使用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() + "');";

1

这是我所做的,只需尝试此操作

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接