Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
?
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
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…
The viewer will learn how to dynamically set the form action using jQuery.
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)

636 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