Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > viewstate and custom control

Reply
Thread Tools

viewstate and custom control

 
 
dave
Guest
Posts: n/a
 
      06-29-2006
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


 
Reply With Quote
 
 
 
 
Riki
Guest
Posts: n/a
 
      07-05-2006
dave wrote:
> 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.

--

Riki


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Failed to load viewstate. The control tree into which viewstate... Josema ASP .Net Building Controls 2 05-22-2005 10:38 AM
Failed to load viewstate. The control tree into which viewstate... Josema ASP .Net Web Controls 0 05-09-2005 10:58 AM
ViewState of the Composite Control composed of custom control whoisnidhee ASP .Net Web Controls 2 07-16-2004 08:05 AM
Difference between PostData and ViewState in a custom control? Henri ASP .Net 2 05-18-2004 05:04 PM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments