Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyperlink OnClick event in code behind

Tags:

c#

asp.net

How to create an OnClick event for hyperlink control?

Can we use Attributes.Add("OnClick","eventname")?

like image 893
Mahesh KP Avatar asked Mar 12 '11 05:03

Mahesh KP


1 Answers

The event is onclick.

You can add it to the hyperlink's mark-up or in the code-behind file.

Mark-up:

<script type="text/javascript" language="javascript">

        function handleHyperLinkClick(hyperlink) {

            return confirm("Do you want to navigate to " + hyperlink.href + " ?");
        }
</script>

<asp:HyperLink ID='HyperLink1' runat="server" onclick='return handleHyperLinkClick(this)' Text='Click Me' NavigateUrl="~/Default.aspx" ></asp:HyperLink>

code-behind:

HyperLink1.Attributes.Add("onclick", "return handleHyperLinkClick(this)");
like image 93
Vijay Sirigiri Avatar answered Nov 01 '22 06:11

Vijay Sirigiri