To extend this thread ... doesn't using an enum in this way cause an ASP.NET page problems?
For example,
<Prefix:MyControl MyChoice="Foo" runat="server" /> throws the exception that the attribute MyChoice needs to be of type enum MyChoice (where it's currently of type String)?
I'm presuming, Andy, that you are the author is this
Flagged Enum Properties blog entry, which addresses this mentioned.
Following your guide, my TextBox server control has ended up like this (trimmed):
Imports System
Namespace e3.Web.UI
Public Class xTextBox
Inherits e3.Web.UI.xWebControl
Implements System.Web.UI.IPostBackDataHandler
' Constructors
Public Sub New()
TagName = "input"
End Sub
' Properties (among others)
Private Property _textBoxMode As e3.Web.UI.TextBoxMode
Get
Dim ThisMode As Object
ThisMode = Me.ViewState( "TextBoxMode" )
If Not ThisMode Is Nothing Then
Return CType( ThisMode, e3.Web.UI.TextBoxMode )
Else
Return e3.Web.UI.TextBoxMode.SingleLine
End If
End Get
Set
Me.ViewState( "TextBoxMode" ) = Value
End Set
End Property
Public Property TextBoxMode As String
Get
Return _textBoxMode.ToString()
End Get
Set
Try
_textBoxMode = CType([Enum].Parse( GetType( e3.Web.UI.TextBoxMode ), Value, True ), e3.Web.UI.TextBoxMode )
Catch
_textBoxMode = e3.Web.UI.TextBoxMode.SingleLine
End Try
End Set
End Property
' Methods
Protected Overrides Sub OnPreRender( ByVal eArgs As EventArgs )
' if the TextBoxMode is MutliLine, then we need to change the TagName to "textarea"
If TextBoxMode.ToLower() = "multiline" Then TagName = "textarea"
End Sub
End Class
' Enums
Public Enum TextBoxMode
SingleLine
MultiLine
Password
End Enum
End Namespace
Is this indeed still the best way to handled enum Properties? Or has a simpler solution presented itself?
(Either way, thanks for your blog, Andy, since it stopped me pulling my hair out.)
Alister