How to init user control?

Posted on 2009-04-23
Last Modified: 2013-11-26
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  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?
Question by:brettr
    LVL 12

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

    Author Comment

    Thanks.  this.DesignMode worked.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
    Flash ( has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now