views:

17

answers:

2

I created user control and want to add it to page. I use next code:

Controls_MultiTextInput cc = new Controls_MultiTextInput();
Controls.Add(cc);

But control doesn't appear on page. What is wrong?

A: 

Anton you can set properties !

Controls_MultiTextInput cc 
   = (Controls_MultiTextInpu)Page.LoadControl("MultiTextInput.ascx");

cc.variable = 2;
cc.SetProperties(223,2311);

Controls.Add(cc);

or

PlaceHolder.Controls.Add(cc);
Aristos
+1  A: 

this.Controls.Add(this.LoadControl("MultiTextInput.ascx")) is the correct way to load the control because it needs to know where the ascx file is.

If you want to set properties, do this:

Controls_MultiTextInput cc = (Controls_MultiTextInput) LoadControl("MultiTextInput.ascx");
cc.MyProperty = "abc";
Controls.Add(cc);
Tim