Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Updated 11-Feb-13 1:34am
v4
Comments
Sergey Alexandrovich Kryukov 9-Feb-13 1:36am    
Do you know JavaScript? What did you try?
I would advice jQuery, then it's really easy.
—SA
Nandakishore G N 9-Feb-13 6:52am    
on what click are you expecting..on label or button click?..can you be little more specific
Karwa_Vivek 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 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 10-Feb-13 5:55am    
Hi,
You can also consider the LinkButton instead of label.

1 solution

Hi,

try using jQuery.

A label generates a div, so this should work:

JavaScript
$(#labelID).click(function(){
  //some code
});


Hope it helps.
 
Share this answer
 
v2
Comments
Karwa_Vivek 11-Feb-13 7:37am    
I didnt undestand what you trying to say.
How should i use this
_Zorro_ 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)



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