Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Custom WebPart: Access Property in User Control Dynamically

  Asked By: Caitlin    Date: Oct 25    Category: Sharepoint    Views: 1369

I am currently trying to write a custom webpart which loads a
usercontrol in the CreateChildControls method.

My webpart has a property which I would like to assign to a property
in the usercontrol.

Here's the code:

protected override void CreateChildControls()
{
MyCustomControl x =
Page.LoadControl("~/_controltemplates/Custom/MyCustomControl.ascx") as
MyCustomControl;
x.CustomProperty = _CustomPropertyFromWebPart; //error here
this.Controls.Add(x);

}

The error I get is "Object reference not set to instance of an object"
when trying to assign the property (based on attaching to the worker
process).

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Christian Waters     Answered On: Oct 25

why dont u use the SmartPart ( that does the same and much friendly )
Also enable debugging on ur code.. u will get the answer

 




Tagged: