How to find server control using jquery?
How to find开发者_如何学运维 server control using jquery e.g
$(".tab1").find("<%=lblTab1Heading.ClientID%>"); throws exception thrown & not caught
You missed the #
for IDs
// here
$(".tab1").find("#<%=lblTab1Heading.ClientID%>");
If for some reason it is not working with the template parser, you can use the $=
selector, like:
$(".tab1").find("[id$=lblTab1Heading]");
jQuery API
- $= (ends with)
- *= (contains)
Try:
var MyControl = $("#<%=lblTab1Heading.ClientID%>");
Because it has an ID, you can simply select it on it's ID which is done with the hash:
$('#ElementID')
You need a # sign in your selector. Try
$(".tab1").find("#<%=lblTab1Heading.ClientID%>");
Though I'm too late for the answer but I guess this code will also help viewers finding it difficult to get the server control ID from JQuery
function GetClientID(id, context) {
var el = $("#" + id, context);
if (el.length < 1)
el = $("[id$=_" + id + "]", context);
return el;
}
and how you should call it
var clientId = GetClientID("serverControlId").attr("id");
var serverControl = document.getElementById(clientId);
精彩评论