Problem solve Get help with specific problems with your technologies, process and projects.

Drop down list server control creates error message

I created a server control that inherits the drop down list control. Basically I wrap up some data access information inside the control. Now all I have to do is drop this control down on a page, set a storedproc and the dropdownlist gets filled. This saves me from having to write all the connection stuff with each drop down I use.

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.

Without having the code to look at, it would be nearly impossible to determine the exact cause of the exception.

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

Dig Deeper on Win Development Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.