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

Author: Imran Akram

A .NET/SharePoint Consultant and a political enthusiast who believes in putting the feet of the elected and/or unelected officials to fire in order to get good governance.

1 thought on “How to get the HTML name attribute of ASP.Net Control”

  1. First is not reliable (I had found few servers that behave rarely with this), but more on this, why we need to go longer, UniqueID does the work

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s