The problem is that when I add this control in design view I get an "Object not set to an instance of an object" dialog box. In the declaration section, I have a reference to a data access business object I wrote. This will take care of running the stored procedure and adding parameters. I also have four methods that mimic the AddParamter methods of the SQLCommand object.
If I override the OnLoad event and create the instance of my DataAccess object there, instead of in the declarations section, everything works fine.
Any ideas why it works when I put it in the OnLoad but not in the declarations? Also, if I put it in the OnLoad, then users can't use this in the Page_Load. They have to use it in the Page_Prerender.
Requires Free Membership to View
When you register, you'll begin receiving targeted emails from my team of award-winning writers. Our goal is to provide a unique online resource for developers, architects and development managers tasked with building and maintaining enterprise applications using Visual Basic, C# and the Microsoft .NET platform.
Hannah Smalltree, Editorial DirectorI would recommend that you review the Control execution lifecycle. If you have the MSDN Library installed, you can find this using the index and the query 'Control Execution Lifecycle', or by simply searching Google for the same phrase.
Do you have comments on this Ask the Expert question and response? Let us know.
This was first published in August 2005