Solved

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

Posted on 2011-02-17
9
967 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

706 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

18 Experts available now in Live!

Get 1:1 Help Now