viewstate and custom control

Discussion in 'ASP .Net Building Controls' started by dave, Jun 29, 2006.

  1. dave

    dave Guest

    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
     
    dave, Jun 29, 2006
    #1
    1. Advertising

  2. dave

    Riki Guest

    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
     
    Riki, Jul 5, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henri
    Replies:
    2
    Views:
    1,737
    Henri
    May 18, 2004
  2. Matt Sokol
    Replies:
    2
    Views:
    411
    Theo Tillotson
    Aug 7, 2003
  3. Josema
    Replies:
    2
    Views:
    375
  4. whoisnidhee

    ViewState of the Composite Control composed of custom control

    whoisnidhee, Jul 14, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    330
    Nidhee
    Jul 16, 2004
  5. Josema
    Replies:
    0
    Views:
    217
    Josema
    May 9, 2005
Loading...

Share This Page