Click here to Skip to main content
13,458,235 members
Click here to Skip to main content
Add your own
alternative version


20 bookmarked
Posted 5 Jul 2007

How To Open a Web Page In a New Browser ASP.NET?

, 5 Jul 2007
Rate this:
Please Sign up or sign in to vote.
Opening web pages in new web browser windows


Many Beginer Web Developers wonder how they can open a new web page in a new web browser and setting some options for it.

In this article I will discuss two methods of opening a new web page in a new web browser. The first method is by using the HyperLink control and the other is by using JavaScript.

Using the HyperLink Control

It is simply an easier way; you only have to set the value of the property "Target" to "_blank" as shown:

Screenshot - Target.jpg

Using JavaScript

This section will be divided it into two sub-sections; they are somehow the same but with minor differences. The sub-sections will be one for the client side controls and the other for the server side controls.

For both we will use the same JavaScript method " )". We will first explain the parameters of this method then know how to use it. The syntax is given below: [sURL] [, sName] [, sFeatures] [, bReplace])
  • URL: Optional. The URL of the page to open in the new window. This argument could be blank.
  • Name: Optional. A name to be given to the new window. The name can be used to refer this window again.
  • Features: Optional. contains a list of items separated by commas. Each item consists of an option and a value, separated by an equals sign (like status bar, address bar etc).
  • Replace: Optional. Boolean that specifies whether the sURL creates a new entry or replaces the current entry in the window's history list. This parameter only takes effect if the sURL is loaded into the same window.

After being familiar to the parameters of the method I will list some of the features that you can use:

fullscreen {yes|no|1|0}Specifies whether to display the browser in full-screen mode.
height number Specifies the height of the window in pixels
left number Specifies the left position, in pixels.
top numberSpecifies the top position, in pixels.
widthnumberspecifies the width of the window in pixels.
location{yes|no|1|0}Specifies whether to display the navigation bar.
menubar {yes|no|1|0}Specifies whether to display the menu bar.
resizable{yes|no|1|0} Allow/Disallow the user to resize the window.
scrollbars{yes|no|1|0} Enable the scrollbars if the document is bigger than the window.
status{yes|no|1|0} Specifies whether to add a Status Bar at the bottom of the window.
titlebar{yes|no|1|0} Specifies whether to display a Title Bar for the window.
toolbar{yes|no|1|0} Specifies whether to display the browser command bar, making buttons such as Favorites Center, Add to Favorites, and Tools available.

First I will talk about using the method in the client side. All what you need to do is to write this line of code in the function of the client side control:

function Button2_onclick() 

This line of code will open the "Default2.aspx" web page in a new browser with the features set on the function parameters.

Second I will talk about using the same method but in the code behind which means in the server side. Lets check this block of code and explain what will happen :

 protected void Button1_Click(object sender, EventArgs e)
      //Part 1 the same code as before
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(>script language='javascript'>");
        sb.Append("'Default2.aspx', 'CustomPopUp',");
        sb.Append("'top=0, left=0, width=500, height=500, menubar=yes,toolbar=yes,status=1,resizable=yes'));

    //Part 2 Registering The ClientScriptBlock
        Type t = this.GetType();

if (!ClientScript.IsClientScriptBlockRegistered(t, PopupScript))
ClientScript.RegisterClientScriptBlock(t, PopupScript, sb.ToString());

In part 1 it is the same code as in the client side subsection. Without part 2 the page "Default2.aspx" will not be opened because you have not register the client script block yet. In the code you check for the script block by its name(key),if not exist then you add it else nothing happens.

I encountered something that I found it helpful.what shall you do if you want to make the new browser open in the maximized mode? You can use the properties "screen.availwidth" and "screen.availheight" to set the widht and height of the features of the method respictivley as follows:

sb.Append('top=0, left=0, width='+screen.availwidth+', height='+screen.availheight+', menubar=yes,toolbar=yes,status=1,resizable=yes'));

I hope this article has been helpful to those of you who queried how to open new web pages in new web browser windows, and I urge those of you who have other comments or tidbits to speak out, and for those with further queries please do not hesitate to ask. Leave a post and we'll get to you as soon as humanly possible!


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


About the Author

Moustafa Zain
Web Developer
Egypt Egypt
.NET Developer
Works now as a SoftwareDeveloper and Trainer

BSc Computer and Information Sciences June 2006.


You may also be interested in...

Comments and Discussions

QuestionHow To Open a Web Page In a New Browser ASP.NET? Pin
mahmoud Noraei9-Sep-12 20:33
membermahmoud Noraei9-Sep-12 20:33 
Questionopen page by typing URL in address bar Pin
kumarjayesh5-Jun-12 1:34
memberkumarjayesh5-Jun-12 1:34 
GeneralMaster page problem Pin
shawpnendu24-Feb-08 23:03
membershawpnendu24-Feb-08 23:03 
GeneralQuickie but good article Pin
ChristopherHenderson7-Sep-07 11:59
memberChristopherHenderson7-Sep-07 11:59 
GeneralRe: Quickie but good article Pin
Moustafa-Mohammed10-Sep-07 4:04
memberMoustafa-Mohammed10-Sep-07 4:04 
GeneralYou could do better Pin
Haissam6-Jul-07 10:58
memberHaissam6-Jul-07 10:58 
GeneralVery Poor Pin
cetinyilmaz6-Jul-07 3:28
membercetinyilmaz6-Jul-07 3:28 
GeneralRe: Very Poor Pin
Moustafa-Mohammed6-Jul-07 3:39
memberMoustafa-Mohammed6-Jul-07 3:39 
GeneralRe: Very Poor Pin
cetinyilmaz6-Jul-07 3:59
membercetinyilmaz6-Jul-07 3:59 
GeneralRe: Very Poor [modified] Pin
Moustafa-Mohammed6-Jul-07 4:10
memberMoustafa-Mohammed6-Jul-07 4:10 
GeneralRe: Very Poor Pin
Mark Nischalke6-Jul-07 7:32
mvpMark Nischalke6-Jul-07 7:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02-2016 | 2.8.180323.1 | Last Updated 6 Jul 2007
Article Copyright 2007 by Moustafa Zain
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid