Sharepoint Forum

 
Home » Forum » Sharepoint       Ask a questionRSS Feeds

Custom WebPart: Access Property in User Control Dynamically

  Asked By: Caitlin Simmons         Date: Oct 25, 2009      Category: Sharepoint      Views: 409
 

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).

Tagged:                

 

1 Answer Found

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

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

 


Your Answer
  • Answer should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].