Archive

Posts Tagged ‘client id by Jquery’

Get Client ID using Jquery

September 20, 2010 1 comment

When we are developing client side in asp.net, we need the id of the controls, but the IDs are merged with master page naming containers.

The id will look something like this

ctl00_MainContent_txtboxId
But using Jquery we can get id like this

$("#<%= <strong>txtboxId</strong>.ClientID %>")
$("[id$=_<strong> txtboxId</strong>]").attr("id")

You can also use the function

function GetClientID(id, context) {
var el = $("#" + id, context);
if (el.length < 1)
el = $("[id$=_" + id + "]", context);
return el;
}

Ex:

GetClientID("txtboxId").attr("id");

Or if I want to be specific about the container:
GetClientID("txtboxId",$("#wrapper")).attr("id");

For More Details Visit: http://www.west-wind.com/Weblog/posts/42319.aspx