Call javascript function on Label clickhttp://forums.asp.net/t/1701620.aspx/1?Call+javascript+function+on+Label+clickWed, 20 Jul 2011 18:27:26 -040017016204515079http://forums.asp.net/p/1701620/4515079.aspx/1?Call+javascript+function+on+Label+clickCall javascript function on Label click <p>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?</p> 2011-07-19T21:27:12-04:004515095http://forums.asp.net/p/1701620/4515095.aspx/1?Re+Call+javascript+function+on+Label+clickRe: Call javascript function on Label click &lt;div&gt; <pre class="prettyprint">&lt;asp:Label id=&quot;myLabel&quot; runat=&quot;server&quot; Text=&quot;My Label&quot; onclick=&quot;myJavascriptFunction();&quot;/&gt;</pre> &lt;/div&gt; &lt;div&gt;Labels render as spans, so if there is no text, it won't have any width, and can therefore not be clicked.&lt;/div&gt; 2011-07-19T21:55:39-04:004515155http://forums.asp.net/p/1701620/4515155.aspx/1?Re+Call+javascript+function+on+Label+clickRe: Call javascript function on Label click <p>Tried but didn't work.</p> 2011-07-20T00:01:56-04:004516676http://forums.asp.net/p/1701620/4516676.aspx/1?Re+Call+javascript+function+on+Label+clickRe: Call javascript function on Label click <p>I'm pretty sure it does. &nbsp;I tested it myself.</p> 2011-07-20T16:40:35-04:004516827http://forums.asp.net/p/1701620/4516827.aspx/1?Re+Call+javascript+function+on+Label+clickRe: Call javascript function on Label click <p>Hi,</p> <p>Please try this:</p> <p>&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;WebForm3.aspx.cs&quot; Inherits=&quot;TestApplication.WebForm3&quot; %&gt;<br> <br> &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br> &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br> &lt;head runat=&quot;server&quot;&gt;<br> &nbsp;&nbsp;&nbsp; &lt;title&gt;&lt;/title&gt;<br> &nbsp;&nbsp;&nbsp; &lt;script type=&quot;text/javascript&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function hello() {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert('Hi, good morning!');<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; &lt;/script&gt;<br> &lt;/head&gt;<br> &lt;body&gt;<br> &nbsp;&nbsp;&nbsp; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp; &lt;div&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Label ID=&quot;lblMsg&quot; onclick=&quot;javascript:hello();&quot; Text=&quot;Click Here&quot;&nbsp;Font-Bold=&quot;true&quot; runat=&quot;server&quot;&gt;&lt;/asp:Label&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/div&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/form&gt;<br> &lt;/body&gt;<br> &lt;/html&gt;</p> 2011-07-20T18:16:10-04:004516833http://forums.asp.net/p/1701620/4516833.aspx/1?Re+Call+javascript+function+on+Label+clickRe: Call javascript function on Label click <p>you don't have to use the &quot;javascript:&quot; prefix. &nbsp;Onclick is assumed to be a javascript event handler.</p> 2011-07-20T18:20:59-04:004516842http://forums.asp.net/p/1701620/4516842.aspx/1?Re+Call+javascript+function+on+Label+clickRe: Call javascript function on Label click <p>Yes I know...thanks anyway.</p> 2011-07-20T18:27:26-04:00