Hyperlink OnClick event in code behind
How to create an OnClick
event for hyperlink contro开发者_StackOverflow中文版l?
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)");
精彩评论