Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 22-Jan-13 1:51am
Comments
Nandakishorerao at 22-Jan-13 6:54am
   
when user clicks on label you have to perform some operation right?
S.Rajendran from Coimbatore at 22-Jan-13 7:03am
   
yes,sure.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can do this by using user control and delegate like below:
 
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);
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try this :
 
 
<script type="javascript">
 
window.onload = function()
{
     document.getElementById("lbl").attachEvent('onclick', function()
     {
            alert("You clicked this label");
     });
}
 
</script>
 
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 305
1 OriginalGriff 225
2 DamithSL 130
3 Kornfeld Eliyahu Peter 130
4 Peter Leow 95
0 OriginalGriff 7,355
1 DamithSL 5,199
2 Sergey Alexandrovich Kryukov 4,942
3 Maciej Los 4,906
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100