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 0: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 OriginalGriff 339
1 _Amy 310
2 Nirav Prabtani 268
3 Sergey Alexandrovich Kryukov 216
4 CHill60 170
0 OriginalGriff 7,889
1 Sergey Alexandrovich Kryukov 7,006
2 Maciej Los 4,014
3 Peter Leow 3,708
4 CHill60 2,762


Advertise | Privacy | Mobile
Web04 | 2.8.140721.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