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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
create wsdl for check policy price 32 35
SP to delete duplicates 15 72
How to get statistic's from a competitors website?! 1 112
Re-position sub-options beneath the TAB 7 98
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to count occurrences of each item in an array.
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)

808 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