Custom Object Property Types

Posted on 2011-05-10
Last Modified: 2012-05-11
I have created a Structure called PageType for a custom control
so far I can programmatically assign by using
myControl.PageType = PageTypes.HomePage
but i'm trying to set the value on the page
<uc:MyPage runat="server" id="myControl" PageType="HomePage" />
but I get the error
"Cannot create an object of type 'PageTypes' from its string representation 'HomePage' for the 'PageType' property."

So it seems it is treating the value HomePage as a string when it is expecting a PageType but I don't know how to set this directly on the object.   In visual studio if I take a textbox and type ForeColor=, it shows everything in System.Drawing.Color but I dont get anything when I type PageType= so I assume its related.
Question by:twcadmin
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    Are the page and the PageType enumeration in the same namespace?
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    Are the page...
    I mean control.
    LVL 5

    Author Comment

    I dont have Enumeration I have used Structure. I register my class on my page and use
    <uc:MyPage runat="server" id="myControl" PageType="HomePage" />
    The control itself is only a Label at the moment. Here is my class file for the custom control.

    Imports System.Data
    Public Structure PageTypes
        'As Friend scope this can be used by internal assemby classes
        'much like Color does within the Drawing namespace classes.
        Friend TypeName As String
        Private Sub New(ByVal _name As String)
            TypeName = _name
        End Sub
        Public Overrides Function ToString() As String
            Return TypeName
        End Function
        Public Shared ReadOnly Property HomePage() As PageTpes
                Return New PageTpes("HomePage")
            End Get
        End Property
        Public Shared ReadOnly Property ContactPage() As PageTypes
                Return New PageTpes("ContactPage")
            End Get
        End Property
    End Structure
    Partial Class MyClass
        Inherits System.Web.UI.UserControl
    Private PageType As PageTypes = PageTypes.HomePage
    Public Property PageType As PageTypes
    Return pPageType
    End Get
    Set (ByVal value As PageTypes)
    pPageType = value
    lblTest.Text = pPageType
    End Set
    End Property
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
    End Class

    Open in new window

    LVL 83

    Accepted Solution

    I know you opted to use Structure for some reason but Enum is the most suitable option in this case. Structure is used to store multiple values of multiple types into one variable. Enum is used for selecting one of the options out of a list.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    728 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

    23 Experts available now in Live!

    Get 1:1 Help Now