How to get the HTML name attribute of ASP.Net Control


//Function to get the HTML name of the server control from the Client Id

// Parameters:

//  clientId – Control.ClientId

//  serverId – Control.id

private string GetHTMLNameById(string clientId, string serverId)

{

int pos = serverId.IndexOf(‘_’);

string HTMLName = “”;

if(pos >= 0)

{

pos = clientId.IndexOf(serverId);

HTMLName = clientId.Remove(pos, serverId.Length);

HTMLName = HTMLName.Replace(‘_’, ‘$’);

HTMLName += serverId;

}

else

HTMLName = clientId.Replace(‘_’, ‘$’);

return HTMLName;

}

Courtesy: http://geekswithblogs.net/Gaurav/archive/2006/09/04/90195.aspx

Advertisements