Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 20, 2011 06:27 PM by vikas-anand
Member
375 Points
325 Posts
Jul 19, 2011 09:27 PM|LINK
I have an asp:Label on my web page. On click on the label, I need to call a javascript function. I don't want to use codebehind for this. Can you please show me how to do this?
Star
12318 Points
2269 Posts
Jul 19, 2011 09:55 PM|LINK
<asp:Label id="myLabel" runat="server" Text="My Label" onclick="myJavascriptFunction();"/>
Jul 20, 2011 12:01 AM|LINK
Tried but didn't work.
Jul 20, 2011 04:40 PM|LINK
I'm pretty sure it does. I tested it myself.
151 Points
67 Posts
Jul 20, 2011 06:16 PM|LINK
Hi,
Please try this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="TestApplication.WebForm3" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function hello() { alert('Hi, good morning!'); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="lblMsg" onclick="javascript:hello();" Text="Click Here" Font-Bold="true" runat="server"></asp:Label> </div> </form> </body> </html>
Jul 20, 2011 06:20 PM|LINK
you don't have to use the "javascript:" prefix. Onclick is assumed to be a javascript event handler.
Jul 20, 2011 06:27 PM|LINK
Yes I know...thanks anyway.
2177
Member
375 Points
325 Posts
Call javascript function on Label click
Jul 19, 2011 09:27 PM|LINK
I have an asp:Label on my web page. On click on the label, I need to call a javascript function. I don't want to use codebehind for this. Can you please show me how to do this?
SP
Please do "Mark As Answer" if this helps you.
AceCorban
Star
12318 Points
2269 Posts
Re: Call javascript function on Label click
Jul 19, 2011 09:55 PM|LINK
2177
Member
375 Points
325 Posts
Re: Call javascript function on Label click
Jul 20, 2011 12:01 AM|LINK
Tried but didn't work.
SP
Please do "Mark As Answer" if this helps you.
AceCorban
Star
12318 Points
2269 Posts
Re: Call javascript function on Label click
Jul 20, 2011 04:40 PM|LINK
I'm pretty sure it does. I tested it myself.
vikas-anand
Member
151 Points
67 Posts
Re: Call javascript function on Label click
Jul 20, 2011 06:16 PM|LINK
Hi,
Please try this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="TestApplication.WebForm3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function hello() {
alert('Hi, good morning!');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblMsg" onclick="javascript:hello();" Text="Click Here" Font-Bold="true" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
AceCorban
Star
12318 Points
2269 Posts
Re: Call javascript function on Label click
Jul 20, 2011 06:20 PM|LINK
you don't have to use the "javascript:" prefix. Onclick is assumed to be a javascript event handler.
vikas-anand
Member
151 Points
67 Posts
Re: Call javascript function on Label click
Jul 20, 2011 06:27 PM|LINK
Yes I know...thanks anyway.