Monday, August 17, 2009

Adding OnClick event to an ASP.NET Label control

It's a strange requirement, but I bumped into it when helping out a user on the forums. Here's how to add an OnClick event to the ASP.NET Label Control
































Now in the Code Behind, use the Control.Attributes.Add() to add the OnClick event to the Label Control

C#


protected void Page_Load(object sender, EventArgs e)

{

Label1.Attributes.Add("onClick", "CallMe();");

}



VB.NET




Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Label1.Attributes.Add("onClick", "CallMe();")

End Sub

No comments:

Post a Comment