Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I want to find all label on my master page and content page in jquery. Labels which i am using on master page and content page are asp.net label.

Thanks,
Posted

1 solution

You can access them using

var l = $("#yourlabelid");


The issue is how you get the label id. If your js is on the same master\content page as your controls you can use

var l = $("#<%= YourControl.ClientID %>");


If it's not, then create a variable on your master\content page that contains the id

var myLabelId = '<%= YourControl.ClientID %>';


You can then use mylabelId in your js

var l = $("#" + mylabelId);


The only thing you need to watch for is that you don't try and use the variable before it is defined.
 
Share this answer
 
Comments
Member 8232678 10-Nov-15 1:43am    
i don't want to use id of indivisual label, i want to find all label control in master page or in content page
F-ES Sitecore 10-Nov-15 4:38am    
jQuery runs on the client, your controls don't exist on the client, only in your server code. All you can do is get a handle of the elements the server controls renders in html. There is no such html concept as a label or any server control. If you give your labels an ID based on a naming convention like "LabelFirstName" and "LabelSecondName" you can use jQuery to get elements whose IDs start with "Label" and that will maybe get what you're after. Use the ^= selector

https://api.jquery.com/category/selectors/

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