Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Using a button and open a new browser  tab in ASP.NET??


Am using this code it's not working

                if (Request.QueryString["newtab"].ToLower() == "true")
                {
                    Response.Redirect("manifestHAWB_Print.aspx");
                }
Posted

You can't open a new window from server code. You have to do it client-side. If you are using an ASP Button you can use:
OnClientClick="window.open('~/manifestHAWB_Print.aspx', target = '_blank');return false;"


If you need to visit the server-side first, then when you're there, just register a startup script with window.open():
ScriptManager.RegisterStartupScript(this, this.GetType(), "launch", "window.open('~/manifestHAWB_Print.aspx', target = '_blank')", true);
 
Share this answer
 
On button click event:

C#
function ButtonClicked() {

    var newWindow = window.open();

}

This will load a new tab in browser without any content. You also can open a new window with your required content.
 
Share this answer
 
Comments
Robert Welliever 28-Oct-14 3:30am    
That won't work. He's using ASP and the button click carries a postback you haven't addressed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900