Open the webpage in new window


On Button click open the webpage in new window

Create the button using the code below
<asp:Button runat="server" id="printPreviewBtn" Text="Print Preview1"  />

On the click of a button if you want to open the resulting webpage in a new window write the following code in Page_Load event.

string url = "dload.aspx ";
string fullURL = "window.open('" + url + "', '_blank', 'height=500,width=800,status=yes,toolbar=no,menubar=yes,location=no,scrollbars=yes,resizable=yes,titlebar=no' );";
printPreviewBtn.Attributes.Add("OnClick",fullURL);

In the above code
height and width refer to the height and width of the window in which the website will open. We can change it to any suitable values.
status refers to wheather we want the status bar on our new window.It can take two values where ‘yes’ means to show the status bar and ‘no’ means to hide the status bar.
toolbar refers to wheather we want to display the toolbar(like goole toolbar etc.) on our new window. It can take two values where ‘yes’ means to show the toolbar and ‘no’ means to hide the toolbar.
menubar refers to wheather we want to display the menubar(file, edit, view, insert etc) on our new window. It can take two values where ‘yes’ means to show the toolbar and ‘no’ means to hide the toolbar.
location here we can specify the locations in terms of x and y points where we want the window to be displayed.
scrollbar refers to wheather we want the scrollbar to be shown for the window. It takes two values where ‘yes’ means to show the scrollbar and ‘no’ means to hide it.
resizable refers to wheather we can resize the window. It can take two values where ‘yes’ means to show the scrollbar and ‘no’ means to hide it.
titlebar refers to wheather we want the titlebar to be shown for the window. It takes two values where ‘yes’ means to show the titlebar and ‘no’ means to hide it.

On Hyperlink click open the webpage in new window.

We have to set the Target property to _blank.This will cause the webpage to open in a new window.
  <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default2.aspx" Target="_blank">HyperLinkasp:HyperLink>

Various values for Target and their meaning as given in MSDN are as follows
_blank
Renders the content in a new window without frames.
_parent
Renders the content in the immediate frameset parent.
_search
Renders the content in the search pane.
_self
Renders the content in the frame with focus.
_top
Renders the content in the full window without frames.

0 comments:

Post a Comment