Hello,
I am using Visual Studio 2012 to create a web part for SharePoint 2010, which will consume a User Control. I am coding in C#. In the User Control, I have designed my web part with various controls from the toolbox. I created the user control itself following the steps in this article:
http://msdn.microsoft.com/en-us/library/vstudio/ee231548(v=vs.110).aspx
And I am setting up my web part .cs file to use the User Control following the example in this article:
http://msdn.microsoft.com/en-us/library/vstudio/ee231577(v=vs.110).aspx
The code in my web part .cs file now looks like this:
private const string _ascxPath = @"~/_CONTROLTEMPLATES/UpdatePanelTestv2/ChartUserControl.ascx"; protected override void CreateChildControls() { base.CreateChildControls(); Control control = Page.LoadControl(_ascxPath); Controls.Add(control); }
When I debug this code, I get unhandled HttpParseException error, 'Object Reference not set to Instance of an Object. on the line "Control control = Page.LoadControl(_ascxPath);"
How can this be? I'm declaring both 'control' and _ascxPath, and stepping through the code in the debugger doesn't show the compiler going anywhere after that line before throwing the error.
I get the same thing if I use "this.Page.LoadControl" also. What gives?
Any help will be greatly appreciated.