Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

Custom Object Property Types

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.
0
twcadmin
Asked:
twcadmin
  • 2
1 Solution
 
käµfm³d 👽Commented:
Are the page and the PageType enumeration in the same namespace?
0
 
käµfm³d 👽Commented:
Are the page...
I mean control.
0
 
twcadminAuthor Commented:
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
        Get
            Return New PageTpes("HomePage")
        End Get
    End Property
    Public Shared ReadOnly Property ContactPage() As PageTypes
        Get
            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
Get 
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
Response.Write(lblTest.Text)
End Sub
End Class

Open in new window

0
 
CodeCruiserCommented:
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now