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
 
Ad

Advertisements

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

Property 1
Custom web control string 2
Problem with type conversion 1
Use property in custom control 1
Property. Control or View State? 1
Check property value 1
Enum 1
Control / Property. Going crazy here. 1

Top