Derived TreeNode LoadViewState not firing

Discussion in 'ASP .Net Web Controls' started by jsc, Jan 12, 2009.

  1. jsc

    jsc Guest

    We're experiencing a problem with LoadViewState not getting fired for
    a derived TreeNode class. We derived the TreeNode class in order to
    add CSSClass property and the initial Page_Load displays the TreeView
    and derived TreeNodes correctly. However, upon PostBack, we get the
    'Failed to Load ViewState....' error and when we set breakpoints, it
    never stops on our LoadViewState override. Also, the SaveViewState
    definitely gets invoked. We've read several discussions regarding
    this issue, but we're yet to find a resolution.

    Below is our code. Are we missing something simple or is this a quirk
    in the 3.5 Framework?

    Thanks in advance!

    Public Class CSSTreeNode
    Inherits System.Web.UI.WebControls.TreeNode

    Public Sub New()
    End Sub

    Public Sub New(ByRef owner As System.Web.UI.WebControls.TreeView,
    IsRoot As Boolean)
    MyBase.New(owner, IsRoot)
    End Sub

    Public Sub New(ByVal text As String, ByVal value As String)
    MyBase.New(text, value)
    End Sub

    Public Sub New(ByVal text As String, ByVal value As String, ByVal
    imageURL As String)
    MyBase.New(text, value, imageURL)
    End Sub

    Private _cssClass As String
    Public Property CssClass() As String
    CssClass = _cssClass
    End Get
    Set(ByVal value As String)
    _cssClass = value
    End Set
    End Property

    Protected Overrides Sub RenderPretext(ByVal writer As
    writer.AddAttribute("class", CssClass)
    End Sub

    Protected Overrides Sub RenderPostText(ByVal writer As
    End Sub

    Protected Overrides Sub LoadViewState(ByVal state As Object)
    If state IsNot Nothing Then
    Dim arStates() As Object = state
    CssClass = arStates(1)
    End If
    End Sub

    Protected Overrides Function SaveViewState() As Object
    Dim arStates(2) As Object
    arStates(0) = MyBase.SaveViewState()
    arStates(1) = CssClass
    Return arStates
    End Function

    End Class
    jsc, Jan 12, 2009
    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.