using Enums as properties in user controls

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
 
G

Göran Andersson

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

Ken Fine

Wow, you're da man, Göran. For once it _wasn't_ my code: a cleaning and
recompile resolved the issue entirely. Thanks!

-KF
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top