Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SubClassing Controls
Message
 
To
28/07/2005 16:45:22
Jim Rieck
Quicken Loans/Rock Financial/Title Sourc
Livonia, Michigan, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Environment versions
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01036765
Message ID:
01037011
Views:
22
Jim,

> I have a dropdown list that is going to retrieve data and populate the dropdown. The dropdownlist is a basic class inherited from the Mere Mortals Dropdownlist control. The problem I am having is that if I place code in the constructor to populate the dropdown and place the control on a webform, the control does appears as a gray box and it says Error Creating Control in red letters. If I put my mouse over the control the tooltip says "object reference not set to the instance of an object". This is, of course, in design mode. The code I am using for the dropdown list class is below.

This is a Visual Studio "issue" (although it IS by design). Visual Studio runs your contorl's constructor at design time. If it can't find the objects it needs at design time, you will see the error you mentioned.sically

The MM .NET Help topic "Why do I get errors when I open a component in design mode?" tells you how to get around this problem. Basically, you need to bracket your constructor code with a check that only runs your code if you are running in design mode. .NET has a built-in DesignMode property that is SUPPOSED to provide this information for you, but it doesn't work during object construction. That's why we have added the IsRunning property to MM .NET.

So, your code will look something like this:
/// <summary>
/// constructor - retrieves desired facility data based on properties.
/// </summary>
public JdaFacilityDropDownList() : base()
{
	//
	// TODO: Add constructor logic here
	//
	if (mmAppBase.IsRunning)
		this.ClientCode  = "BSC";
		this.oFacility = new Facility();
		this.GetFacilitiesByCustomerId(this.ClientCode);
		this.BindingSource = "Facility";
		this.BindingSourceDisplayMember = "Descr";
		this.BindingSourceValueMember = "Fac_Num";
	}
}
Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform