Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 !!

like image 552
dotnetrocks Avatar asked Dec 16 '22 05:12

dotnetrocks


2 Answers

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() + "');";
like image 65
Zaki Avatar answered Jan 01 '23 15:01

Zaki


this is what i done, just try this

ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('ViewDetails.aspx','mywindow','menubar=1,resizable=1,width=900,height=600');", true);
like image 43
anandd360 Avatar answered Jan 01 '23 14:01

anandd360