DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Generate Client Id In Javascript
// description of your code here
// calling code: GenerateClientIDVariables(txtCountryCode, txtStateCode, txtPhoneNo);
private void GenerateClientIDVariables(params Control[] controlArray)
{
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), this.GetType().FullName))
{
var clientIDs = new StringBuilder();
var declaration = "var {0}='{1}';";
foreach (Control ctrl in controlArray)
{
if (ctrl.ClientID != null && ctrl.ID != null && ctrl.Visible)
{
clientIDs.AppendFormat(declaration, ctrl.ID, ctrl.ClientID);
}
}
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), this.GetType().FullName, clientIDs.ToString(), true);
}
}




