简体   繁体   中英

open asp.net page in new window

I'm trying to open asp.net page in new window while loading itself. I tried with the following code. But it is opening in the same window not in the new window.

     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";

            }


        }
    }

Any help is appreciated. thanks !!

Use a Javascript in code behind to redirect :

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

Or use ScriptManager and you can pass parameters too:

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

Or if you have a button you can use it as below:

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

这就是我所做的,试试吧

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM