Retrieve .Net Control ID in Javascript
- by Vipin
Originally posted on: http://geekswithblogs.net/Vipin/archive/2013/07/24/retrieve-.net-control-id-in-javascript.aspxIf you need to retrieve a client ID of an asp:net control in a javascript function, then you can use the below function - function $$(id, context) {
var el = $("#" + id, context);
if (el.length < 1)
el = $("[id$=_" + id + "]", context);
return el;
}
var tempDotNetControl = 'aspTextTemporary';
var ClientSideID = $$(aspTextTemporary);
Please bear in mind, this function is useful if you want to retrieve client ID of a different DotNet control based on some condition, otherwise if it’s always static then you can just use <%= aspTextTemporary.ClientID %>"