On which Page life cycle are the Client IDs generated?

i am programatically adding Webcontrols in to a User Control i am also adding a javascript event passing the controlID as a parameter but the clientID is the one i assigned a it does not contain the one that asp.net generates

   var txt = new TextBox();
   txt.ID = "MyID"+Number;

   chkBox.Attributes.Add("onClick", "EnableTxtBox('" +txt.ClientID + "');");

i can workAround this by adding the parent control ID

   chkBox.Attributes.Add("onClick", "EnableTxtBox('" + this.ClientID+"_"+txt.ClientID + "');");

On which Page life cycle are the Client IDs generated?

Answers


You need to add the control to the control hierarchy before you add the attribute.

   var txt = new TextBox();
   txt.ID = "MyID"+Number;
   Controls.Add ( txt );
   chkBox.Attributes.Add("onClick", "EnableTxtBox('" +txt.ClientID + "');");

ControlCollection is no ordinary collection; it notifies the owner control when controls are added, and the control can take appropriate actions.


Need Your Help

c# add a picture to excel from resources

c# excel resources interop

I'm currently doing the below to add an image to an excel file I'm creating via "interop"

Best practices for configuring Apache / Tomcat

java apache tomcat jboss mod-proxy

We are currently using Apache 2.2.3 and Tomcat 5 (Embedded in JBoss 4.2.2) using mod_proxy_jk as the connector.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.