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
214 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 125 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now