On what page life cycle are client identifiers generated?

I programmatically add Webcontrols to a user control. I also add a javascript event that passes the controlID as a parameter, but the client ID - the one I assigned to it does not contain the one that asp.net emits

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

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

I can work around this by adding a parent control id

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

On what page life cycle are client identifiers generated?

+5
source share
2 answers

Before adding an attribute, you must add the control to the control hierarchy.

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

ControlCollection ; , , .

+7

OnPreRender(). INamingContainer ...

+2

All Articles