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

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

I wanted to do something like this:

My Label
10条回答
  •  粉色の甜心
    2020-12-15 04:14

    You can use Attributes to add onclick client side callback.

    I didn't know you can do this on span tags, but if it works you can add 'onclick' by lblMyLabel.Attributes.Add("onclick", "foo();");

    But foo(); would need to be a client side javascript function.

    System.Web.UI.WebControls.Label does NOT have OnClick server event. You could look into using AJAX if you want server callback with example above.

    You could also use LinkButton like other say. You can make it not look like a link by using CSS, if it is just that underline you are concerned about.

    ASPX:

    
    LinkButton
    
    

    CSS:

    a.imjusttext{ color: #000000; text-decoration: none; }
    a.imjusttext:hover { text-decoration: none; }
    

提交回复
热议问题