The preferred .NET Framework method for adding an attribute (e.g. onClick) to the webcontrol is:
control.Attributes.Add("onclick", "javascript:DoSomething('" + control.Value + "')")
You can also add an onClick event when another event is fired (e.g. DataBound):
Private Sub ctlControlName_ActionName(ByVal sender As Object, ByVal e As System.EventArgs) Handles ctlControlName.ActionName Dim control As ControlType = DirectCast(sender, ControlType) control.Attributes.Add("onclick", "javascript:DoSomething('" + control.Value + "')") End Sub
Hope this helps!
source share