Call Javascript Function inside asp:Hyperlink Control

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.

One thought on “Call Javascript Function inside asp:Hyperlink Control

  • February 11, 2008 at 4:43 pm
    Permalink

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

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: