jvcoach23
jvcoach23

Reputation: 3037

Jquery and asp.net masterpages

I thought i saw an example recently that would allow you to use jquery with asp.net and master pages so you didn't have to have the full name of an object.

For example, say you had a label in a master page. when you view the source that name might be "ct100_lblName". if you reference it in JQuery, you need to use that full ct100_lblName. This is where i was thinking i saw where you could put something in your jquery where you made that reference and use some jquery magic and lblName.

Am i way off here. Thanks Shannon

Upvotes: 0

Views: 83

Answers (2)

Akos Lukacs
Akos Lukacs

Reputation: 2047

You can get the clientID in aspx, and use it like this:

var clientIdOfTheLabel = "<%=lblName.ClientID%>";
var $label = $("#" + clientIdOfTheLabel);

Or add css class to your labels, and access your elements using css selectors. Something like var $labels = $(".myInterestingLabels");

Upvotes: 0

Alex Dn
Alex Dn

Reputation: 5553

You can use "ends" selector:

$("span[id$=lblName]")

But you should use "context" argument to get more accurate result, otherwise selector may return more objects that you expect.

$("span[id$=lblName]", "#myDiv")

http://api.jquery.com/attribute-ends-with-selector/

Upvotes: 1

Related Questions