Is there a way to add an onclick event to an ASP.NET Label server control?

前端 未结 10 1052
不思量自难忘°
不思量自难忘° 2020-12-15 03:30

I wanted to do something like this:

My Label
10条回答
  •  盖世英雄少女心
    2020-12-15 04:11

    Your question doesn't specify if you mean to raise the click event on the server (VB or c#) or the client (javascript.) If you're looking for a server-side event you should use a link button with css that makes the link appear as a label. You can then use the link button's server-side click event. If you're looking for a client-side click event - just type it into your server control markup
    asp:label id="MyLabel" runat="server" onclick="javascript:alert('hello');" Text="Click Me";
    ASP.NET will emit additional attributes in the html markup that generates.

提交回复
热议问题