<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function CallMe() {
alert('Hi');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
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
You saved me a couple of hours!
ReplyDeletecan nayone tell me how to play songs on click event in asp.net application .i have ten mp3 songs which i have to play on the click event.plase help me.
ReplyDeletesend me reply on siddhu.chauhan30@gmail.com
Could you please explain how to catch the event? I just get a java error now and adding a sub in VB.net does not work (adding a sub CallMe).
ReplyDelete