Can a HyperLink bring up a JavaScript window?

Posted on 2005-04-08
Last Modified: 2010-04-07

I have a HyperLink with the following attribute on MyBase.Load:
        Me.HyperLink1.Attributes.Add("onclick", "javascript:new_window('index.aspx', 40, 300)")

The following KavaScript code WORKS.


<script language="JavaScript">

          var url="index.aspx";
          function new_window(url,iWidth,iHeight) {

          link =,"newWindow","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=500,left=140,top=50");


PROBLEM: If I don't set the NavigateUrl property of the Hyperlink in design time and just simply to the attribute, when the page runs the Hyperlink is not a link at all, it's just text. Now, if I set the NavigateUrl property to the same page it will do a roundtrip and I don't want it tobecause there is no need to. On the other hand if I don't set it at all it comes out as plain text.

 I don't want to use a botton.

What should I do?
Thanks in advance

Question by:avikatz16
    LVL 44

    Accepted Solution

    Hi avikatz16,

            Me.HyperLink1.Attributes.Add("onclick", "javascript:new_window('index.aspx', 40, 300);return false;")

    Adding return false; should stop it doing the postback if you set the NavigateURL property to the current page or even "#"

    Tim Cottee
    LVL 1

    Author Comment

    LVL 1

    Author Comment

    could you please assist me just a little further?
    in the page the opens how can i have it open lets say at a table in the middle of the page?
    LVL 44

    Expert Comment


    Use an internal anchor in the page just above the table:

    <a name="OpenHere">
    <table> .......

    Then your destination URL would be something like ""

    The #OpenHere is telling the browser to go to the destination anchor on the new page.

    LVL 1

    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    759 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

    8 Experts available now in Live!

    Get 1:1 Help Now