viewstate and custom control

D

dave

I have custom control with dropdownlist. I am using this custom control in a
repeater. After the post-back the control properties that i stored in
viewstate does not exist. They are all empty.

When, where and how does viewstate get set with custom control? I would
have expected that when i return the value of a property using something like
the following the viewstate would have existed.

Public Property DataTextField() As String
Get
If CType(ViewState("DataTextField"), Object) Is Nothing Then
Return _dataTextField
Else
Return CType(ViewState("DataTextField"), String)
End If
End Get
Set(ByVal value As String)
ViewState("DataTextField") = value
Me.DropDownList.DataTextField = value
_dataTextField = value
End Set
End Property

Also, i thought the dropdownlist would have maintained it's own state but it
did not after postback. Any ideas?
thx
dave
 
R

Riki

dave said:
I have custom control with dropdownlist. I am using this custom
control in a repeater. After the post-back the control properties
that i stored in viewstate does not exist. They are all empty.

When, where and how does viewstate get set with custom control? I
would have expected that when i return the value of a property using
something like the following the viewstate would have existed.

Public Property DataTextField() As String
Get
If CType(ViewState("DataTextField"), Object) Is
Nothing Then Return _dataTextField
Else
Return CType(ViewState("DataTextField"), String)
End If
End Get
Set(ByVal value As String)
ViewState("DataTextField") = value
Me.DropDownList.DataTextField = value
_dataTextField = value
End Set
End Property

Also, i thought the dropdownlist would have maintained it's own state
but it did not after postback. Any ideas?
thx
dave

First of all, does the control still exist after the postback?
If so, does it have exactly the same ID after the postback compared to
before?
If not, it will not be able to restore viewstate.

You can check this by turning Trace on and checking the control tree.

Apart from that, viewstate should work without any further coding.
 

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

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top