HighTechTalks DotNet Forums  

viewstate and custom control

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss viewstate and custom control in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
dave
 
Posts: n/a

Default viewstate and custom control - 06-29-2006 , 01:15 PM






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
  #2  
Old   
Riki
 
Posts: n/a

Default Re: viewstate and custom control - 07-05-2006 , 04:57 AM






dave wrote:
Quote:
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 Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.