?
Solved

I need to open a  Hyperlink(In a new browser window),when user click a button in asp.net by using c#.

Posted on 2004-09-13
3
Medium Priority
?
310 Views
Last Modified: 2010-05-18
I need to add feature like when user click a button i need to open a hyperlink in a new browser window.How can i transfer html <a target=_blank  href=" " ></a> from code behind.
0
Comment
Question by:paresha
3 Comments
 

Expert Comment

by:Maldini
ID: 12050681
btnClick.Attributes.Add("onclick", "window.open('GiftWindow.aspx');");
Should be something like this, I work in VB.net mostly.

hth
0
 
LVL 3

Expert Comment

by:xakem
ID: 12052460
or
<input type="submit" value="open" onClick="window.open('mywindow.xxx', 'myWin')">
0
 
LVL 14

Accepted Solution

by:
tomaugerdotcom earned 375 total points
ID: 12054925
Couple of ways this can be done. The easiest is as xakem suggests, though I would recommend changing the type to "button" not "submit" (it might not make a difference functionally, but it's better formed code).

So, if you want to open a new window with the hyperlink "my_web_page.html" then the code is:
<input type="button" value="CLICK FOR NEW WINDOW" onClick="window.open('my_web_page.html')">

Note that whatever you set the "value" parameter to will be the text the button displays.

If you need more control over the window that will open (for example, you want to set the window to a specific size), you might use a little JavaScript to make it easier:

First, you have to define your "window opening function" using JavaScript, so put this in-between the <head></head> tags of your web page. If you don't have <head></head> tags, better start using them! And you're not forgetting your <title></title> tags right?

<html>
<head>
  <title>My Web Page Title</title>
  <script type="text/javascript" language="javascript">
    function openNewWindow(whichURL) {
       config='toolbar=no,location=no,directories=no,status=no,menubar=no,width=385,height=290,scrollbars=no,resizable=yes';
       window.open (whichURL, "myNewWindow", config);
      }
    </script>
</head>
<body>
 some stuff.....
  <p>Click here for a   new window <input type="button" value="CLICK ME" onClick="openNewWindow('my_web_page.html')"></p>
</body>
</html>

So what's going on in the JavaScript function? Well, a couple of cool things.
1 cool thing is the config parameter which lets you control all sorts of attributes of your new window, like whether the user can resize it, whether there are scrollbars, what the size is.
Another cool thing is that you can re-use this function for any url. when you call the function using onClick="openNewWindow()" just put the URL inside the brackets (don't forget to use single quotes).

Hope this gives you some options.

Tom Auger
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question