views:

35

answers:

1

I have a custom ASP.NET user control that is added to a panel on a web page in the Page.Load method. The control contains some Labels and a GridView. I'm adding it to the page with this code:

ReportingControl rc = new ReportingControl(this.Username, this.SoaContext, transactionId, p.PaymentTypeRequestKey);
this.pnlPB.Controls.Add(rc);

For some reason, the controls that are added aren't actually showing up on the page. I also noticed that the controls within the control are all null but I don't know if that is part of the problem or if they are created at a later time. Any ideas?

+1  A: 

Is it a UserControl or a custom server control inheriting from CompositeControl, WebControl, etc.?

Generally with user controls, you load them via the ascx location, such as:

//load the control
Control rc= LoadControl("~/UserControls/MyControl.ascx");

//set up values as needed
rc.Username = this.Username; 

//add the control where needed
this.pnlPB.Controls.Add(rc);
KP
Yep, You're right.
matt-dot-net
yep - ascx files need to be compiled, not just instantiated.
dave thieben
This is absolutely right! Thanks so much!
rwponu