Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
I have 12 labels
in a aspx page
how can i get the Text of
any label when is clicked.
I have Tried using the Click event of every label
But the coding is getting more.
Is there any Other option or idea
to fetch the text .
Please Assist any Idea.
Am using following Code to get the text on every click event of labels.
Dim str as String 
str =label1.text.tostring
Msgbox(str)
but this way I have to create events on every 12 labels.
But i think there must be some another way to handle this
may be writing some functions.
Please assist.
Posted 8-Feb-13 20:11pm
Edited 11-Feb-13 2:34am
v4
Comments
Sergey Alexandrovich Kryukov at 9-Feb-13 1:36am
   
Do you know JavaScript? What did you try?
I would advice jQuery, then it's really easy.
—SA
Nandakishorerao at 9-Feb-13 6:52am
   
on what click are you expecting..on label or button click?..can you be little more specific
Karwa_Vivek at 9-Feb-13 7:02am
   
On click event of Label .I want to fetch the text of that Particular label which is clicked.
Gunjan Bhasin at 10-Feb-13 2:40am
   
you want it to be done on label's click event and you mentioned 'you have tried using click event of button?' hard to understand. please be specific. Paste code if possible.
Muthuraja Irullandi at 10-Feb-13 5:55am
   
Hi,
You can also consider the LinkButton instead of label.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
try using jQuery.
 
A label generates a div, so this should work:
 
$(#labelID).click(function(){
  //some code
});
 
Hope it helps.
  Permalink  
v2
Comments
Karwa_Vivek at 11-Feb-13 7:37am
   
I didnt undestand what you trying to say.
How should i use this
_Zorro_ at 11-Feb-13 7:51am
   
Well, you'll have to do a bit of research, take a look at jQuery and you'll understand.
Otherwise take a look at this: http://stackoverflow.com/questions/181097/is-there-a-way-to-add-an-onclick-event-to-an-asp-net-label-server-control

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

  Print Answers RSS
0 Maciej Los 230
1 OriginalGriff 202
2 Richard MacCutchan 185
3 Tomas Takac 146
4 CPallini 125
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 11 Feb 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