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
251 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

821 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