Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to know if there is any possibility of using a label control for click event in asp.net. If not, can anyone help guiding with javascript code.
In certain pages I have already used button control for the click event.

Regards.
Posted
Comments
Nandakishore G N 22-Jan-13 6:54am    
when user clicks on label you have to perform some operation right?
S.Rajendran from Coimbatore 22-Jan-13 7:03am    
yes,sure.

Try this :

JavaScript
<script type="javascript">

window.onload = function()
{
     document.getElementById("lbl").attachEvent('onclick', function()
     {
            alert("You clicked this label");
     });
}

</script>
 
Share this answer
 
Why do you want to mock the behavior of button using label? The simplest thing would be to create a css class and apply it to the button to make it look like label(without border and background color etc.)
 
Share this answer
 
You can do this by using user control and delegate like below:

C#
public delegate void MyClick (object
sender, System.EventArgs e);
public event MyClick cClick ;

private void UserControl1_Click(object
sender, System.EventArgs e)
{
if (cClick != null)
cClick (sender,e);
}

private void label1_Click(object sender,
System.EventArgs e)
{
UserControl1_Click( sender, e);
}

private void label2_Click(object sender, System.EventArgs
e)
{
UserControl1_Click( sender, e);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900