using Enums as properties in user controls

  • Thread starter Thread starter Ken Fine
  • Start date Start date
K

Ken Fine

Hi, I have what I think is a simple type conversion problem.

I am building user controls. In the VS.NET IDE I want to be able to use
enumerations when assigning properties. I do this by building an
enumeration:

public enum PageProtectionMode { NoProtection, LimitToAccountHolders,
LimitToSpecialAccountHolders, LimitByRoles,
LimitToCommaDelimitedListOfUsernames }

.... and by building a property that uses that enumeration:
private PageProtectionMode pageprotectionmodechoice;
public PageProtectionMode PageProtectionModeChoice
{
get { return pageprotectionmodechoice); }
set { pageprotectionmodechoice = value; }
}

The above code functions in the IDE, and I get intellisense when editing the
non-codebehind ASCX but when I try to run it, I get:
Cannot create an object of type
'_usercontrols_general_AdminGeneralOverview+PageProtectionMode' from its
string representation 'LimitToSpecialAccountHolders'

Somewhere in this I'm guessing I either need an "Parse.Enum" or something
like it, or maybe I'm bumping into a hard limit of the behavior of user
controls. Can anyone suggest some code or syntax to help?

-KF
 
Ken said:
Hi, I have what I think is a simple type conversion problem.

I am building user controls. In the VS.NET IDE I want to be able to use
enumerations when assigning properties. I do this by building an
enumeration:

public enum PageProtectionMode { NoProtection, LimitToAccountHolders,
LimitToSpecialAccountHolders, LimitByRoles,
LimitToCommaDelimitedListOfUsernames }

... and by building a property that uses that enumeration:
private PageProtectionMode pageprotectionmodechoice;
public PageProtectionMode PageProtectionModeChoice
{
get { return pageprotectionmodechoice); }
set { pageprotectionmodechoice = value; }
}

The above code functions in the IDE, and I get intellisense when editing
the non-codebehind ASCX but when I try to run it, I get:
Cannot create an object of type
'_usercontrols_general_AdminGeneralOverview+PageProtectionMode' from its
string representation 'LimitToSpecialAccountHolders'

Somewhere in this I'm guessing I either need an "Parse.Enum" or
something like it, or maybe I'm bumping into a hard limit of the
behavior of user controls. Can anyone suggest some code or syntax to help?

-KF

No, there is nothing more needed. The compiler should parse the value
just fine.

I think that there is some problem with the compilation of your project.
Check so that you don't have any other error that is keeping the user
control from being compiled. Try the Clean option from the Build menu.
Try restaring Visual Studio.
 
Wow, you're da man, Göran. For once it _wasn't_ my code: a cleaning and
recompile resolved the issue entirely. Thanks!

-KF
 
Back
Top