Click hyperlink programmatically

Posted on 2009-04-23
Last Modified: 2013-11-07
I have an <a> tag in an aspx page with onclick javascript attached to it.  I also have a button with a subroutine in the code behind doing some stuff.  I want the user to click the button, do the sub, then have it click that <a> automatically to do the javascript.  How can I do this?  I've tried casting the <a> as an mshtml.IHTMLElement, then using the .click action, but that didn't work.

Basically I found a javascript (GB_Show) called Greybox which pops a great preview window that I want the Account Detail page to show in.   Just clicking the link works great, but I need to do a database update and set a session variable, thus the need for a sub in the code behind.
code behind for the button:

  Public Sub btnRedirect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRedirect.Click

        Dim f As mshtml.IHTMLElement = DirectCast(Me.TestA, mshtml.IHTMLElement)

    End Sub

code for the front end of the button and the anchor

 <asp:Button  ID="btnRedirect" runat="server" Text="Acknowledge and go to Account Detail" Width="300" />

                          <a id="TestA" runat="server" onclick="return GB_show('Account detail', 'http://webserver/account_detail.aspx', 600, 800)" >

                                                            Email - outbound</a>

Open in new window

Question by:flagshipcredit
    LVL 83

    Expert Comment


    Author Comment

    No dice with the onclick.

    Accepted Solution

    I figured it out...I removed the <a> completely, and used ScriptManager.RegisterStartupScript on the button.


    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

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now