views:

7

answers:

0

I have a curious problem with a .net usercontrol which is probably some page lifecycle issue that I've missed, but I'd be grateful for some advice.

The control has a "showContributor" boolean property which is supposed to turn some columns in the display on or off. It consists of a repeater control containing other custom usercontrols to represent the rows. Each of these controls also has a showContributor property.

In the top-level control I'm doing this on data binding:

Private Sub rptbrowsertree_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptbrowsertree.ItemDataBound
    Dim ucCategoryRow As CategoryRow
    Select Case e.Item.ItemType
        Case ListItemType.Header
            ucCategoryRow = DirectCast(e.Item.FindControl("ucCategoryRow"), CategoryRow)
            ucCategoryRow.ShowContributor = showContributor
            ucCategoryRow.Category = _categorytree
        Case ListItemType.Item
            Dim category As CMS.DataTransferObjects.Category = DirectCast(e.Item.DataItem, CMS.DataTransferObjects.Category)
            ucCategoryRow = DirectCast(e.Item.FindControl("ucCategoryRow"), CategoryRow)
            ucCategoryRow.ShowContributor = showContributor
            ucCategoryRow.Category = category
            ucCategoryRow.RowClass = "row"
        Case ListItemType.AlternatingItem
            Dim category As CMS.DataTransferObjects.Category = DirectCast(e.Item.DataItem, CMS.DataTransferObjects.Category)
            ucCategoryRow = DirectCast(e.Item.FindControl("ucCategoryRow"), CategoryRow)
            ucCategoryRow.ShowContributor = showContributor
            ucCategoryRow.Category = category
            ucCategoryRow.RowClass = "altrow"
    End Select
End Sub

In other words I get the repeater item, cast it, and set it's showContributor property to be the same as that of the parent control before setting category and class. If you step through this section of the code you'll see it goes into the code of the row control and sets the property as expected.

Now the row control is a multi-view control. It has a behaviour property which tells it which view to use, and as part of setting this property I'm also setting whether the Contributor columns should show, like this:

Public Property Behaviour() As browsertree.CategoryRowBehaviour
    Get
        Return _behaviour
    End Get
    Set(ByVal value As browsertree.CategoryRowBehaviour)
        _behaviour = value
        Select Case Behaviour
            Case browsertree.CategoryRowBehaviour.header
                pnlContributorHead.Visible = ShowContributor
                mvwCategoryRow.SetActiveView(vwheader)
            Case browsertree.CategoryRowBehaviour.datarow, browsertree.CategoryRowBehaviour.headerrow
                pnlContributorRow.Visible = ShowContributor
                mvwCategoryRow.SetActiveView(vwdatarow)
        End Select
    End Set
End Property

Now this section of code is stepped through after the showContributor property is set during the item databinding. But when I come to step through this, the local value of showContributor is always false.

What's going on here? Why isn't the property remembering the value it was set to?