开发者

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)");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜