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?
brettrAsked:
Who is Participating?
 
GuitarRichConnect With a Mentor Commented:
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.
0
 
brettrAuthor Commented:
Thanks.  this.DesignMode worked.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.