Enum Problem

S

shapper

Hello,

I have a custom control property named "ImagePosition".
I need to have only two options available for this property: "Left" and
"Top".

How can I do this?

Thanks,
Miguel

My Code:
' ImagePosition
<Bindable(True), Category("Layout"), DefaultValue(""),
Localizable(True)> Property ImagePosition() As String
Get
Dim sImagePosition As String = CStr(ViewState("ImagePosition"))
If sImagePosition Is Nothing Then
Return String.Empty
Else
Return sImagePosition
End If
End Get

Set(ByVal Value As String)
ViewState("ImagePosition") = Value
End Set

End Property
 
M

Mike

First off, create the Enum declaration

public enum Position
{
Left = 1,
Top = 2
}

Then update your property to that datatype instead of a string.

public Position ImagePosition
{
get
{
object o = ViewState[this.ClientID + "_ImagePosition"];
if (o != null) //check if it was set
return (Position)o; //cast to correct type
else
return Position.Left; //default value
}
set
{
ViewState[this.ClientID + "_ImagePosition"] = value;
}
}

This is C# code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Problem with type conversion 1
Color problem 0
Property 1
Custom web control string 2
Use property in custom control 1
Enum and the designer 0
Check property value 1
Property. Control or View State? 1

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top