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 = ??
var rcno = document. getElementById('<%=recno. ClientID %>'); But it return null value..
The Button control has an OnClientClick event which you could use to call some js-code for all buttons. e.g. <asp:Button id="button1" OnClientClick="test(this.id)" ... var fu1 = document.
Getting Client ID of ASP.Net control using jQuery Once the file is added copy the following code into the JS file. Finally you need to reference the JS file in your project where you need to get the ClientID. return $("[id$=" + asp_net_id + "]"). attr("id");
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';
var labelID = $('#<%= label1.ClientID %>');
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.
var labelID = '<%= label1.ClientID %>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With