Problem with LoadViewState

Discussion in 'ASP .Net Building Controls' started by IgorW, Oct 10, 2003.

  1. IgorW

    IgorW Guest

    Hallo NG,

    I have problem with the methode LoadViewState.
    I develop a custom DataBound control, which create other DataBound
    Controls.
    That is the TabStrip and TabStripRow. The TabStripRow create the
    TabStripRowItem.
    After PostBack the method LoadViewState in TabStrip was called but not in
    TabStripRow.
    Have anybody a idea why the method LoadViewState in TabStripRow are not
    called?
    The SaveViewState works without problems.

    Thanks

    Igor
     
    IgorW, Oct 10, 2003
    #1
    1. Advertisements

  2. Did TabStrip ever create its child controls?
     
    John Saunders, Oct 10, 2003
    #2
    1. Advertisements

  3. IgorW

    Igor Guest

    yes, at databinding with datavalues, at postback should that read the values
    from ViewState.
     
    Igor, Oct 10, 2003
    #3
  4. Ok, but you need to store in ViewState everything necessary to recreate the
    controls as they were at the end of the last postback. This not only
    includes the ViewState of all the child controls, it also includes
    everything you need to create the child controls. For instance, if you
    created a number of tabs based on the data you were bound to, then you will
    need to store the number of tabs in ViewState. On PostBack, you'll read the
    number of tabs and create that many tabs and add them to the Controls
    collection of the TabStrip. The individual tabs will read their own
    ViewState, but you will have to create them first!
     
    John Saunders, Oct 11, 2003
    #4
  5. IgorW

    IgorW Guest

    yes, I du it exactly the same, as they say.
    TabStrip overrides method SaveViewState and LoadViewState.

    <
    Protected Overrides Function SaveViewState() As Object
    Dim NewState As New ArrayList
    With NewState
    .Add(MyBase.SaveViewState())
    .Add(m_RowCount)
    End With
    Return NewState
    End Function

    Protected Overrides Sub LoadViewState(ByVal savedState As Object)
    Dim OldState As ArrayList = CType(savedState, ArrayList)
    MyBase.LoadViewState(OldState.Item(0))
    m_RowCount = OldState.Item(1)
    End Sub
    and the TabStipRow Overrides this methods
    <
    Protected Overrides Sub LoadViewState(ByVal savedState As Object)
    Dim OldState As ArrayList = CType(savedState, ArrayList)
    MyBase.LoadViewState(OldState.Item(0))
    m_RowItemsCount = OldState.Item(1)
    End Sub
    Protected Overrides Function SaveViewState() As Object
    Dim NewState As New ArrayList
    With NewState
    .Add(MyBase.SaveViewState)
    .Add(m_RowItemsCount)
    End With
    Return NewState
    End FunctionAt First call are the SaveViewState() called as as usual and the
    RowItemsCount are saved to ViewState.
    but at PostBack is the Value <this(or in VB "Me").ViewState[1]> =
    "null"(in VB "Nothing") and the void LoadViewState are not called.
    Do you know, what is important for ViewState?

    Thanks,

    Igor


    Am Fri, 10 Oct 2003 21:58:23 -0400 hat John Saunders <john.saunders at
    surfcontrol.com> geschrieben:
     
    IgorW, Oct 12, 2003
    #5
  6. I've never used an ArrayList to store view state. Try using an array of
    objects instead:

    Dim NewState As New Object(2)
    NewState(0) = MyBase.SaveViewState()
    NewState(1) = m_RowItemsCount
     
    John Saunders, Oct 12, 2003
    #6
  7. IgorW

    IgorW Guest

    Ok, I try it out.
    But I have a control, that used the ArrayList for ViewState - it works.
    in the Wrox book "Professional ASP.Net Server Controls (Programmer to
    Programmer)" are written that the ArrayList are provided type for
    ViewState.

    salute

    Igor

    Am Sun, 12 Oct 2003 09:50:21 -0400 hat John Saunders <john.saunders at
    surfcontrol.com> geschrieben:
     
    IgorW, Oct 12, 2003
    #7
  8. IgorW

    IgorW Guest

    Hi,
    I tried it with object array, but that don't helps.
    any other idea?

    salute

    Igor

     
    IgorW, Oct 13, 2003
    #8
  9. My only idea is to try just putting m_RowCount directly into ViewState like
    "ViewState("RowCount") = m_RowCount".
    --
    John Saunders
    Internet Engineer



     
    John Saunders, Oct 13, 2003
    #9
  10. IgorW

    IgorW Guest

    I tried it already.
    meanwhile, I found out, that if I create the TabStrip without use of
    VS.NET designer - thus by hand:
    Instantiate the TabStrip in Page_Init method and set the DataSource. so I
    get the call of LoadViewState in TabStripRow and TabSripRowItem.
    And here occurs the next problem: If I add the TabStrip by hand, how can I
    control the position of it, if other controls are created with designer? I
    mean - not the CSS, but Index in the Controls collection. If I use the
    Method AddAt(index, control), I lost the control tree, with all the
    consequences following from it.

    oh,... my English [;-((
    sorry

    Am Mon, 13 Oct 2003 08:40:35 -0400 hat John Saunders <john.saunders at
    surfcontrol.com> geschrieben:
     
    IgorW, Oct 13, 2003
    #10
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.