Over a million developers have joined DZone.

Generate Client Id In Javascript

DZone's Guide to

Generate Client Id In Javascript

Free Resource
// 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);

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}