473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

using Enums as properties in user controls

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
2 3170
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mohandas P.M | last post by:
Hi, We have a prob with .Net User Controls, something like this. I have a Custon Control InfoLabel Derived from System.Windows.Forms.Label ( Direct Inheritance - Custom Control) and the some...
0
by: Bob Avallone | last post by:
I have created a user control (aspc). I want the user of the control (aspx) to be able to pass a property to the control at runtime. I think I'm close but I don't have it quite right. Here are...
2
by: Luke Ward | last post by:
Hi All I created web user control that has a few properties and an Update method. These controls all get initialised and configured (all properties set) at the page load event. Today I...
0
by: Jim | last post by:
I am having some trouble with user controls and would appreciate any input / advice on where to go with this... :) 1. The first problem, and perhaps the root of the others, is that I have...
6
by: Earl Teigrob | last post by:
I am writing an application that dynamically loads user controls at run time based on user options. I would like to give my users the ability to build their own user controls and add them to my...
2
by: badger | last post by:
Hi, I have created a usercontrol with a public property as follows: // default display type to single form. private DisplayType selectedDisplayType = LoginForm.DisplayType.SingleForm; ...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
8
by: | last post by:
I'm looking for some design guidance on a collection of projects I'm working on. The project involves a bunch of websites constructed out of a collection of user controls. Different user...
11
by: Web Search Store | last post by:
Hello, I set up a web page with 2 user controls. In classic asp, the first one did all the declarations, and the second one used the values, and could reset it. In ASP.Net so far I can't...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.