retrieve ID of server control using jQuery

AGuyCalledGerald picture AGuyCalledGerald · Apr 14, 2011 · Viewed 21.5k times · Source

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 = ??

Answer

pstarkov picture pstarkov · Apr 14, 2011

If you use ASP.NET 4.0 you can set attribute ClientIDMode="Static" and your code will looks following way:

<asp:Label ID="label1" runat="server" ClientIDMode="Static"></asp:Label>

js:

var id = 'label1';