How do I get the ID of a server control with jQuery?
E.g. I have
<asp:Label ID="label1" runat="server""></asp:Label>
and now I want to get "label1",
var id = ??
How do I get the ID of a server control with jQuery?
E.g. I have
<asp:Label ID="label1" runat="server""></asp:Label>
and now I want to get "label1",
var id = ??
jQuery runs on the client side so would only be able to access the ID of the html element rather than the asp control on the server.
You need to get the client ID.
If you just need the ID, and not the actual value of the control, then you don't even need jQuery.
If you use ASP.NET 4.0 you can set attribute ClientIDMode="Static" and your code will looks following way:
js:
Labels render as span tags. So if you want to select all the Labels:
Are you using master page. If yes give ContentPlaceHolderID along with control id.
Eg:
You can see this in Viewsource