By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,007 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,007 IT Pros & Developers. It's quick & easy.

using Enums as properties in user controls

P: n/a
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+PagePr otectionMode' 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

Sep 11 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ken Fine wrote:
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+PagePr otectionMode' 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.

--
Göran Andersson
_____
http://www.guffa.com
Sep 11 '08 #2

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

-KF

"Göran Andersson" <gu***@guffa.comwrote in message
news:Of**************@TK2MSFTNGP05.phx.gbl...
Ken Fine wrote:
>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+PageP rotectionMode' 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.

--
Göran Andersson
_____
http://www.guffa.com
Sep 11 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.