Wednesday, February 3, 2010

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;
    }

No comments:

Post a Comment