Solved

Opening the navigate url in a new browser instead of redirecting in the same browser

Posted on 2011-02-17
9
968 Views
Last Modified: 2012-05-11
I have asp:hyperlink in my webpage. Onclick I would like to open this in a new window instead of redirecting in the same browser.
Basically I would like to have the same effect as having an input button and on click calling the attached javascript function showwindow(). Please suggest how can I call this javascript function from the click of the asp:hyperlink. should I rather use any other html control . Please help thanks

<asp:HyperLink ID="hlPrintCart" NavigateUrl="/showwindow.aspx" runat="server">Print page</asp:HyperLink>      
function ShowWindow()
                        {
                        var h = 500;
                        var w = 600;        
                        PackingSlipPopUp = window.open("showwindow.aspx","_blank","scrollbars=yes,toolbar=yes,resizable=yes,location=no,status=no,width=" + w + ",height=" + h + ",top= " + ((screen.height - h) / 5) + ",left=" + ((screen.width - w) / 2));
                        PackingSlipPopUp.focus();
                        }
0
Comment
Question by:TrialUser
9 Comments
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 34923405
simple:

NavigateUrl="javascript:ShowWindow()"
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34923414
this may work too

<asp:HyperLink ID="hlPrintCart" NavigateUrl="#" onClick="ShowWindow()" runat="server">Print page</asp:HyperLink>
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34923419
or

<asp:HyperLink ID="hlPrintCart" NavigateUrl="#" runat="server">Print page</asp:HyperLink>

vb code:
hlPrintCart.attributes.add("onClick","ShowWindow()");
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34923424
or, why do you need server control for this? use simple <a> element

<a href="#" onClick="ShowWindow()">Print page</a>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:Anurag Agarwal
ID: 34923679
hello TrialUser !! instaed of using everything just use this ......

<asp:HyperLink ID="hlPrintCart" NavigateUrl="/showwindow.aspx" runat="server" Target="_blank">Print page</asp:HyperLink>  

for reference look http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlink.target.aspx
0
 
LVL 8

Expert Comment

by:Anurag Agarwal
ID: 34923685
no javascripts will be required in this case .............!!
0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 34924546
Hi, you have to use


target="_blank"
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34926673
target="_blank" is not he wants I guess:

if you look at this code

window.open("showwindow.aspx","_blank","scrollbars=yes,toolbar=yes,resizable=yes,location=no,status=no,width=" + w + ",height=" + h + ",top= " + ((screen.height - h) / 5) + ",left=" + ((screen.width - w) / 2));

he wants to open it in a NICE window, not in a new window :) this is what I get... and thats why he has that open function...
0
 

Author Closing Comment

by:TrialUser
ID: 34928117
perfect thx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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 …

911 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

26 Experts available now in Live!

Get 1:1 Help Now