Home All Groups Group Topic Archive Search About

CompositeControl Property Persisted But Not Reflected At Run/Desig

Author
23 Aug 2006 2:28 PM
swalkertdci
I have a compositecontrol derived class that I am working on that exposes
several design-time properties. Most of these properties simply delegate to a
corresponding child control property. In most cases this works just fine in
both the designer and runtime. However for two properties on my control
CSSClass and RibbonGroupTitle, I can see the values I set in the designer
persited to the HTML, but after switching to source view and back, the value
I set is not correctly refelected in the designer, or at runtime. I'm sure
there is something really simple I'm missing here, but if someone could help
me find the problem that would be fantastic.  The code is as follows:

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.ComponentModel.Design

<ToolboxData("<{0}:RibbonGroup runat=server></{0}:RibbonGroup>"), _
ParseChildren(True), _
Designer("TDCIRibbonBar.RibbonGroupDesigner, TDCIRibbonBar",
GetType(IDesigner))> _
Public Class RibbonGroup
    Inherits CompositeControl

    Private moContainerTable As Table
    Private moTableContentRow As TableRow
    Private moTableContentCell As TableCell
    Private moTableTitleRow As TableRow
    Private moTableTitleCell As TableCell
    Private molblTitle As Label
    Private moContentTemplate As ITemplate

    <Browsable(True), _
    Category("Appearance"), _
    Description("Style for the inner table area.")> _
    Public Property InnerTableCSSClass() As String
        Get
            EnsureChildControls()
            Return moContainerTable.CssClass
        End Get
        Set(ByVal value As String)
            EnsureChildControls()
            moContainerTable.CssClass = value
        End Set
    End Property

    <Browsable(True), _
    Category("Appearance"), _
    Description("Style for the title area.")> _
    Public Property TitleAreaCSSClass() As String
        Get
            EnsureChildControls()
            Return moTableTitleCell.CssClass
        End Get
        Set(ByVal value As String)
            EnsureChildControls()
            moTableTitleCell.CssClass = value
        End Set
    End Property

    <Browsable(True), _
    Category("Appearance"), _
    Description("Style for the content area.")> _
    Public Property ContentAreaCSSClass() As String
        Get
            EnsureChildControls()
            Return moTableContentCell.CssClass
        End Get
        Set(ByVal value As String)
            EnsureChildControls()
            moTableContentCell.CssClass = value
        End Set
    End Property

    <Browsable(True), _
    Category("Appearance"), _
    Description("Alignment of the group title area."), _
    PersistenceMode(PersistenceMode.Attribute)> _
    Public Property TitleAlignment() As VerticalAlign
        Get
            Dim oValue As Object = ViewState("TitleAlignment")
            If oValue Is Nothing Then Return VerticalAlign.Bottom Else
Return oValue
        End Get
        Set(ByVal value As VerticalAlign)
            If value = VerticalAlign.Middle Or value = VerticalAlign.NotSet
Then
                Throw New NotSupportedException(String.Format("Value {0} is
not a supported value.", value))
            Else
                ViewState("TitleAlignment") = value
                MyBase.ChildControlsCreated = False
                EnsureChildControls()
            End If
        End Set
    End Property

    <Browsable(True), _
    Category("Appearance"), _
    Description("Group title text.")> _
    Public Property RibbonGroupTitle() As String
        Get
            EnsureChildControls()
            Return molblTitle.Text
        End Get
        Set(ByVal value As String)
            EnsureChildControls()
            molblTitle.Text = value
        End Set
    End Property

    'TODO: Do we need this? TemplateContainer(typeof(GridViewRow))]
    <Browsable(False), _
    PersistenceMode(PersistenceMode.InnerProperty)> _
    Public Property ItemTemplate() As ITemplate
        Get
            Return moContentTemplate
        End Get
        Set(ByVal value As ITemplate)
            moContentTemplate = value
        End Set
    End Property

    Protected Overrides Sub CreateChildControls()
        MyBase.CreateChildControls()

        Controls.Clear()
        CreateControlHierarchy()
        ClearChildViewState()
    End Sub

    Protected Sub CreateControlHierarchy()
        Me.CssClass = "RibbonGroup"

        moContainerTable = New Table()
        moContainerTable.CssClass = "RibbonGroupInnerTable"
        moContainerTable.CellPadding = 0
        moContainerTable.CellSpacing = 0
        moContainerTable.BorderWidth = 0

        moTableContentRow = New TableRow()
        moTableContentCell = New TableCell()
        moTableTitleRow = New TableRow()
        moTableTitleCell = New TableCell()
        molblTitle = New Label()

        moTableTitleCell.CssClass = "RibbonGroupTitleArea"
        molblTitle.Text = "Title Area"
        moTableTitleCell.Controls.Add(molblTitle)
        moTableTitleRow.Controls.Add(moTableTitleCell)
        moTableContentCell.CssClass = "RibbonGroupContentArea"
        moTableContentRow.Controls.Add(moTableContentCell)

        ' make sure we have controls to put in the content
        If Not moContentTemplate Is Nothing Then
            moContentTemplate.InstantiateIn(moTableContentCell)
        Else
            moTableContentCell.Controls.Add(New LiteralControl("Content
Area"))
        End If

        Select Case Me.TitleAlignment
            Case VerticalAlign.Bottom
                moContainerTable.Rows.Add(moTableContentRow)
                moContainerTable.Rows.Add(moTableTitleRow)
            Case VerticalAlign.Top
                moContainerTable.Rows.Add(moTableTitleRow)
                moContainerTable.Rows.Add(moTableContentRow)
        End Select

        Me.Controls.Add(moContainerTable)
    End Sub

    Friend Sub GetDesignTimeHTML()
        Me.EnsureChildControls()
    End Sub

    Protected Overrides ReadOnly Property TagKey() As
System.Web.UI.HtmlTextWriterTag
        Get
            Return HtmlTextWriterTag.Div
        End Get
    End Property

End Class


Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design

Public Class RibbonGroupDesigner
    Inherits ControlDesigner

    Dim moTemplateColl As TemplateGroupCollection = Nothing

    Public Overrides Sub Initialize(ByVal component As
System.ComponentModel.IComponent)
        MyBase.Initialize(component)

        'enable template editing
        SetViewFlags(ViewFlags.TemplateEditing, True)
    End Sub

    Public Overrides Function GetDesignTimeHtml() As String
        Dim ctl As RibbonGroup = CType(Me.Component, RibbonGroup)
        ctl.getdesigntimehtml()
        Return MyBase.GetDesignTimeHtml()
    End Function

    Public Overrides ReadOnly Property TemplateGroups() As
System.Web.UI.Design.TemplateGroupCollection
        Get
            If moTemplateColl Is Nothing Then
                moTemplateColl = MyBase.TemplateGroups

                Dim tempGroup As TemplateGroup = Nothing
                Dim tempDef As TemplateDefinition = Nothing
                Dim ctl As RibbonGroup = Nothing

                ' get component reference
                ctl = CType(Me.Component, RibbonGroup)

                'create a template group
                tempGroup = New TemplateGroup("ItemTemplate")

                ' create a template definition
                tempDef = New TemplateDefinition(Me, "ItemTemplate", ctl,
"ItemTemplate", True)

                ' add template definition to the template group
                tempGroup.AddTemplateDefinition(tempDef)
                moTemplateColl.Add(tempGroup)
            End If

            Return moTemplateColl

        End Get
    End Property

    Public Overrides ReadOnly Property AllowResize() As Boolean
        Get
            Return True
        End Get
    End Property


End Class


..RibbonGroup
{
    width:200px;
    height:100px;
    float:left;
    border-width: 1px;
    border-color: #4A79C6;
    border-style: solid;
}

..RibbonGroupInnerTable
{
    height:100%;
    width:100%;
    padding: 0px 0px 0px 0px;
}

..RibbonGroupTitleArea
{
    height:20%;
    width:100%;
    text-align: center;
    color: #4A79C6;
    font-weight:bold;
    font-size: small;
    filter:
progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#EFEBE7,endColorStr=#C6DBEF);
}

..RibbonGroupContentArea
{
    height:80%;
    width:100%;
    filter:
progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#EFEBE7,endColorStr=#FFFBFF);
}

Author
23 Aug 2006 2:44 PM
swalkertdci
Another problem is that if the first thing I do on the control is edit the
template, the template will show up ok in the designer. As soon as I change
any of the custom properties on my control, the designer no longer renders
the template.

Show quoteHide quote
"swalkertdci" wrote:

> I have a compositecontrol derived class that I am working on that exposes
> several design-time properties. Most of these properties simply delegate to a
> corresponding child control property. In most cases this works just fine in
> both the designer and runtime. However for two properties on my control
> CSSClass and RibbonGroupTitle, I can see the values I set in the designer
> persited to the HTML, but after switching to source view and back, the value
> I set is not correctly refelected in the designer, or at runtime. I'm sure
> there is something really simple I'm missing here, but if someone could help
> me find the problem that would be fantastic.  The code is as follows:
>
> Imports System.Web
> Imports System.Web.UI
> Imports System.Web.UI.WebControls
> Imports System.ComponentModel
> Imports System.ComponentModel.Design
>
> <ToolboxData("<{0}:RibbonGroup runat=server></{0}:RibbonGroup>"), _
> ParseChildren(True), _
> Designer("TDCIRibbonBar.RibbonGroupDesigner, TDCIRibbonBar",
> GetType(IDesigner))> _
> Public Class RibbonGroup
>     Inherits CompositeControl
>
>     Private moContainerTable As Table
>     Private moTableContentRow As TableRow
>     Private moTableContentCell As TableCell
>     Private moTableTitleRow As TableRow
>     Private moTableTitleCell As TableCell
>     Private molblTitle As Label
>     Private moContentTemplate As ITemplate
>
>     <Browsable(True), _
>     Category("Appearance"), _
>     Description("Style for the inner table area.")> _
>     Public Property InnerTableCSSClass() As String
>         Get
>             EnsureChildControls()
>             Return moContainerTable.CssClass
>         End Get
>         Set(ByVal value As String)
>             EnsureChildControls()
>             moContainerTable.CssClass = value
>         End Set
>     End Property
>
>     <Browsable(True), _
>     Category("Appearance"), _
>     Description("Style for the title area.")> _
>     Public Property TitleAreaCSSClass() As String
>         Get
>             EnsureChildControls()
>             Return moTableTitleCell.CssClass
>         End Get
>         Set(ByVal value As String)
>             EnsureChildControls()
>             moTableTitleCell.CssClass = value
>         End Set
>     End Property
>
>     <Browsable(True), _
>     Category("Appearance"), _
>     Description("Style for the content area.")> _
>     Public Property ContentAreaCSSClass() As String
>         Get
>             EnsureChildControls()
>             Return moTableContentCell.CssClass
>         End Get
>         Set(ByVal value As String)
>             EnsureChildControls()
>             moTableContentCell.CssClass = value
>         End Set
>     End Property
>
>     <Browsable(True), _
>     Category("Appearance"), _
>     Description("Alignment of the group title area."), _
>     PersistenceMode(PersistenceMode.Attribute)> _
>     Public Property TitleAlignment() As VerticalAlign
>         Get
>             Dim oValue As Object = ViewState("TitleAlignment")
>             If oValue Is Nothing Then Return VerticalAlign.Bottom Else
> Return oValue
>         End Get
>         Set(ByVal value As VerticalAlign)
>             If value = VerticalAlign.Middle Or value = VerticalAlign.NotSet
> Then
>                 Throw New NotSupportedException(String.Format("Value {0} is
> not a supported value.", value))
>             Else
>                 ViewState("TitleAlignment") = value
>                 MyBase.ChildControlsCreated = False
>                 EnsureChildControls()
>             End If
>         End Set
>     End Property
>
>     <Browsable(True), _
>     Category("Appearance"), _
>     Description("Group title text.")> _
>     Public Property RibbonGroupTitle() As String
>         Get
>             EnsureChildControls()
>             Return molblTitle.Text
>         End Get
>         Set(ByVal value As String)
>             EnsureChildControls()
>             molblTitle.Text = value
>         End Set
>     End Property
>
>     'TODO: Do we need this? TemplateContainer(typeof(GridViewRow))]
>     <Browsable(False), _
>     PersistenceMode(PersistenceMode.InnerProperty)> _
>     Public Property ItemTemplate() As ITemplate
>         Get
>             Return moContentTemplate
>         End Get
>         Set(ByVal value As ITemplate)
>             moContentTemplate = value
>         End Set
>     End Property
>
>     Protected Overrides Sub CreateChildControls()
>         MyBase.CreateChildControls()
>
>         Controls.Clear()
>         CreateControlHierarchy()
>         ClearChildViewState()
>     End Sub
>
>     Protected Sub CreateControlHierarchy()
>         Me.CssClass = "RibbonGroup"
>
>         moContainerTable = New Table()
>         moContainerTable.CssClass = "RibbonGroupInnerTable"
>         moContainerTable.CellPadding = 0
>         moContainerTable.CellSpacing = 0
>         moContainerTable.BorderWidth = 0
>
>         moTableContentRow = New TableRow()
>         moTableContentCell = New TableCell()
>         moTableTitleRow = New TableRow()
>         moTableTitleCell = New TableCell()
>         molblTitle = New Label()
>
>         moTableTitleCell.CssClass = "RibbonGroupTitleArea"
>         molblTitle.Text = "Title Area"
>         moTableTitleCell.Controls.Add(molblTitle)
>         moTableTitleRow.Controls.Add(moTableTitleCell)
>         moTableContentCell.CssClass = "RibbonGroupContentArea"
>         moTableContentRow.Controls.Add(moTableContentCell)
>
>         ' make sure we have controls to put in the content
>         If Not moContentTemplate Is Nothing Then
>             moContentTemplate.InstantiateIn(moTableContentCell)
>         Else
>             moTableContentCell.Controls.Add(New LiteralControl("Content
> Area"))
>         End If
>
>         Select Case Me.TitleAlignment
>             Case VerticalAlign.Bottom
>                 moContainerTable.Rows.Add(moTableContentRow)
>                 moContainerTable.Rows.Add(moTableTitleRow)
>             Case VerticalAlign.Top
>                 moContainerTable.Rows.Add(moTableTitleRow)
>                 moContainerTable.Rows.Add(moTableContentRow)
>         End Select
>
>         Me.Controls.Add(moContainerTable)
>     End Sub
>
>     Friend Sub GetDesignTimeHTML()
>         Me.EnsureChildControls()
>     End Sub
>
>     Protected Overrides ReadOnly Property TagKey() As
> System.Web.UI.HtmlTextWriterTag
>         Get
>             Return HtmlTextWriterTag.Div
>         End Get
>     End Property
>
> End Class
>
>
> Imports System
> Imports System.ComponentModel
> Imports System.Web.UI
> Imports System.Web.UI.WebControls
> Imports System.Web.UI.Design
>
> Public Class RibbonGroupDesigner
>     Inherits ControlDesigner
>
>     Dim moTemplateColl As TemplateGroupCollection = Nothing
>
>     Public Overrides Sub Initialize(ByVal component As
> System.ComponentModel.IComponent)
>         MyBase.Initialize(component)
>
>         'enable template editing
>         SetViewFlags(ViewFlags.TemplateEditing, True)
>     End Sub
>
>     Public Overrides Function GetDesignTimeHtml() As String
>         Dim ctl As RibbonGroup = CType(Me.Component, RibbonGroup)
>         ctl.getdesigntimehtml()
>         Return MyBase.GetDesignTimeHtml()
>     End Function
>
>     Public Overrides ReadOnly Property TemplateGroups() As
> System.Web.UI.Design.TemplateGroupCollection
>         Get
>             If moTemplateColl Is Nothing Then
>                 moTemplateColl = MyBase.TemplateGroups
>
>                 Dim tempGroup As TemplateGroup = Nothing
>                 Dim tempDef As TemplateDefinition = Nothing
>                 Dim ctl As RibbonGroup = Nothing
>
>                 ' get component reference
>                 ctl = CType(Me.Component, RibbonGroup)
>
>                 'create a template group
>                 tempGroup = New TemplateGroup("ItemTemplate")
>
>                 ' create a template definition
>                 tempDef = New TemplateDefinition(Me, "ItemTemplate", ctl,
> "ItemTemplate", True)
>
>                 ' add template definition to the template group
>                 tempGroup.AddTemplateDefinition(tempDef)
>                 moTemplateColl.Add(tempGroup)
>             End If
>
>             Return moTemplateColl
>
>         End Get
>     End Property
>
>     Public Overrides ReadOnly Property AllowResize() As Boolean
>         Get
>             Return True
>         End Get
>     End Property
>
>
> End Class
>
>
> .RibbonGroup
> {
>     width:200px;
>     height:100px;
>     float:left;
>     border-width: 1px;
>     border-color: #4A79C6;
>     border-style: solid;
> }
>
> .RibbonGroupInnerTable
> {
>     height:100%;
>     width:100%;
>     padding: 0px 0px 0px 0px;
> }
>
> .RibbonGroupTitleArea
> {
>     height:20%;
>     width:100%;
>     text-align: center;
>     color: #4A79C6;
>     font-weight:bold;
>     font-size: small;
>     filter:
> progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#EFEBE7,endColorStr=#C6DBEF);
> }
>
> .RibbonGroupContentArea
> {
>     height:80%;
>     width:100%;
>     filter:
> progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#EFEBE7,endColorStr=#FFFBFF);
> }
>
>