How to create an OnClick
event for hyperlink control?
Can we use Attributes.Add("OnClick","eventname")
?
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)");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With