what I learn is what u c

Call Javascript Function inside asp:Hyperlink Control

with 8 comments

If you ever want to call a javascript function (with or without  parameter) from a server side hyperlink control here it is..

Step 1 :

declare your javascript function between

Step 2:

<asp:HyperLink ID=”hypCate” runat=”server”

NavigateUrl='<%# “javascript:showPopUp(” & DataBinder.Eval(Container.DataItem, “ID”) & “);” %>’

Text='<%#DataBinder.Eval(Container.DataItem, “Name”)%>’ />

Carefully follow the single and double quotes for NavigateUrl attribute.

Needless to say showPopUp is the name of Javascript Function.

It displays the NAME as hyperlink. Clicking that calls javascript showPopUp.

Written by gchandra

September 27, 2007 at 4:55 pm

8 Responses

Subscribe to comments with RSS.

  1. How do you add single quotes around DataBinder.Eval(). I need to pass the value to my javascript function.

    Scott Minor

    February 11, 2008 at 4:43 pm

  2. Above script on asp hyperling control has really helped me a lot.


    June 5, 2008 at 11:25 pm

  3. Hi,

    The above post is very helpful, it has helped me a lot.


    Ujjwal B Soni

    Ujjwal B Soni

    September 13, 2008 at 12:51 am

  4. Thanks mate, that helped a lot!!


    January 6, 2009 at 8:37 am

  5. Works! Thanks


    June 15, 2009 at 5:44 am

  6. here is the c# version
    just replace & with +

    <asp:HyperLink Runat='server' ID='lnkFile'

    M Ali

    August 18, 2009 at 10:27 am

  7. <asp:HyperLink Runat='server' ID='lnkFile'

    M Ali

    August 18, 2009 at 10:28 am

  8. Same problem like what Scott said, “How do you add single quote around DataBinder.Eval()”


    April 26, 2011 at 5:57 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: