• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

How to init user control?

In .NET winforms 3.5, I have a user control that I need to set its visibility property.  Visibility is set based on the result of a method call on a singleton.  In the control constructor, I do this:

//in constructor
visible = mysingleton.IsAuthorized(Operation);

The user control also has this property:

public Operations Operation {get;set;}

which is available to set at design time in the control's properties, in vs.net.  It has a value either way since it is an enum.

The problem is that once I drop the control onto a form, it throws exceptions such as:

System.ArgumentException: Value does not fall within the expected range.

Commenting out the line in the constructor works fine.  Where else can I call this line of code so it works declaratively?
1 Solution
does it fail at design time or runtime? If it is design time you can check for that before the visible call by checking this.DesignMode in the user control. Also you could makesure the UserControls Operation property has a default value set.
brettrAuthor Commented:
Thanks.  this.DesignMode worked.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now