I've got a web part that loads a user control in the CreateChildControls
method. I would like to assign a value to a property in my user
control, but I'm having difficulty doing so. Here's the code:
protected override void CreateChildControls()
{
MyCustomControl x =
Page.LoadControl("~/_controltemplates/Custom/MyCustomControl.ascx") as
MyCustomControl;
x.MyControlProperty = "some value"; //error occurs at this
statement
this.Controls.Add(x);
}
For some reason I get an "Object Reference not set to an instance of an
object" when I try to assign the value to the property. So how do I
set this value dynamically?