Property. Control or View State?


S

shapper

Hello,

I am creating a control which I will compile in a class.
I am having problems when I use a property in the View State:

' Items
<Bindable(True), Category("Data"), DefaultValue(""),
Localizable(True)> _
Property Items() As Generic.List(Of String)
Get
If ViewState("Items") Is Nothing Then
Return New Generic.List(Of String)
Else
Return ViewState("Items")
End If
End Get
Set(ByVal Value As Generic.List(Of String))
ViewState("Items") = Value
End Set
End Property ' Items

But I don't get problems if I use it in Control State:

Private _Items As New Generic.List(Of String)
Public Property Items() As Generic.List(Of String)
Get
Return _Items
End Get
Set(ByVal value As Generic.List(Of String))
_Items = value
End Set
End Property ' Items

Anyway, this is a little bit confusing to me.
Could someone tell me which one should I use?
I am working on ASP.NET 2.0.

Thanks,
Miguel
 
Ad

Advertisements

M

marss

shapper said:
Hello,

I am creating a control which I will compile in a class.
I am having problems when I use a property in the View State:

' Items
<Bindable(True), Category("Data"), DefaultValue(""),
Localizable(True)> _
Property Items() As Generic.List(Of String)
Get
If ViewState("Items") Is Nothing Then
Return New Generic.List(Of String)
Else
Return ViewState("Items")
End If
End Get
Set(ByVal Value As Generic.List(Of String))
ViewState("Items") = Value
End Set
End Property ' Items

I guess all the problems are caused by continuous creation of a new
List object
every time you ask for Items property. Try this:

Property Items() As Generic.List(Of String)
Get
If ViewState("Items") Is Nothing Then ViewState("Items") = New
Generic.List(Of String)
Return ViewState("Items")
End Get
Set(ByVal Value As Generic.List(Of String))
ViewState("Items") = Value
End Set
End Property

Regards, Mykola
http://marss.co.ua
 

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. Which one should I use? 3
Property 1
Control / Property. Going crazy here. 1
Custom web control string 2
Property. 3
Property problem. Please, need some help on this. 1
CheckBox 1
Is Nothing problem 16

Top