Designer Property Serialization -- Sycning inner properties to designer property window

A

Alexander Higgins

Hi,

I am just getting started developing custom user controls, and I am
having issues keep the inner properties of nested controls in sync
with the properties in the designer window. When I change a property
of a nested control in the properties window, the designer does not
automatically redraw itself. If I switch to HTML Mode and then return
to design mode, the control is redrawn. But If I switch back to HTML
Mode the inner properties are not updated.

However, If I change a property of my custom control or the font-bold
property of the nested control in the design window, the nested
control is refreshed and the inner properties are correctly updated.
How do I keep the two in sync? Am I missing something here? Do I
need to implement a TypeConverter and set NotifyParentProperty(True)
to keep the designer in sync with the properties window. If I do, how
can I implement one for web controls as I will have several controls
and do not feel like coding a wrapper for every property of every
control on the page. Or, is there some why to manually fire the event
that is raised when the nested control's font-bold is changed in the
properties window.

Also, what is the difference between refresh.repaint and refresh.all.
Does one only redraw the control on the designer while the other
recreates the controls properties and then redraws the control on the
designer?

Here is my code in the simplest form. Thanks for the help in
advance...

Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
<Assembly: TagPrefix("Editor", "cms")>
<ParseChildren(True), Designer("System.Web.UI.Design.ControlDesigner,
System.Design"), DefaultProperty("Text"), ToolboxData("<cms:Editor
runat=server></cms:Editor>"),
RefreshProperties(RefreshProperties.Repaint)> Public Class Editor
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer

Dim _text As String

<Bindable(True), Category("Appearance"), DefaultValue("")>
Property [Text]() As String
Get
Return _text
End Get

Set(ByVal Value As String)
_text = Value
End Set

End Property
Private _TitleLabel As Label
<Category("CMS"), Bindable(True),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
RefreshProperties(RefreshProperties.Repaint),
NotifyParentProperty(True),
PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property [TitleLabel]() As Label
Get

Return _TitleLabel
End Get
Set(ByVal Value As Label)

_TitleLabel = Value
Me.ChildControlsCreated = False
Me.EnsureChildControls()

End Set
End Property
 
T

Teemu Keiski

One thing that pops up is that if the Label exposed by the TitleLabel
property is actually created in CreateChildControls, the property would need
to be read-only. If you change that first, does it help at all?

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


Alexander Higgins said:
Hi,

I am just getting started developing custom user controls, and I am
having issues keep the inner properties of nested controls in sync
with the properties in the designer window. When I change a property
of a nested control in the properties window, the designer does not
automatically redraw itself. If I switch to HTML Mode and then return
to design mode, the control is redrawn. But If I switch back to HTML
Mode the inner properties are not updated.

However, If I change a property of my custom control or the font-bold
property of the nested control in the design window, the nested
control is refreshed and the inner properties are correctly updated.
How do I keep the two in sync? Am I missing something here? Do I
need to implement a TypeConverter and set NotifyParentProperty(True)
to keep the designer in sync with the properties window. If I do, how
can I implement one for web controls as I will have several controls
and do not feel like coding a wrapper for every property of every
control on the page. Or, is there some why to manually fire the event
that is raised when the nested control's font-bold is changed in the
properties window.

Also, what is the difference between refresh.repaint and refresh.all.
Does one only redraw the control on the designer while the other
recreates the controls properties and then redraws the control on the
designer?

Here is my code in the simplest form. Thanks for the help in
advance...

Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
<Assembly: TagPrefix("Editor", "cms")>
<ParseChildren(True), Designer("System.Web.UI.Design.ControlDesigner,
System.Design"), DefaultProperty("Text"), ToolboxData("<cms:Editor
runat=server></cms:Editor>"),
RefreshProperties(RefreshProperties.Repaint)> Public Class Editor
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer

Dim _text As String

<Bindable(True), Category("Appearance"), DefaultValue("")>
Property [Text]() As String
Get
Return _text
End Get

Set(ByVal Value As String)
_text = Value
End Set

End Property
Private _TitleLabel As Label
<Category("CMS"), Bindable(True),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
RefreshProperties(RefreshProperties.Repaint),
NotifyParentProperty(True),
PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property [TitleLabel]() As Label
Get

Return _TitleLabel
End Get
Set(ByVal Value As Label)

_TitleLabel = Value
Me.ChildControlsCreated = False
Me.EnsureChildControls()

End Set
End Property
 
A

Alexander Higgins

Thanks for the suggestion. I tries not understanding the logic, but
in any case it did not help. Making the property readonly prevents
the ability to set its properties at all. I must create the control
during the CreateChildControls events and after that what is set can
not be changed.

I am not trying to do anything complex here, I am simply making a
composite control. I need to offer the developers the ability to
modify the composites child controls via HTML Mode,and with the
properties window in Visual Studio.Net.

I just can't figure out why the property changes on the nested control
do not update globally when the changes are made. Even more
frustrating is in VS 2005 the properties chnages via the property
window are not refelected at all.

One thing that pops up is that if the Label exposed by the TitleLabel
property is actually created in CreateChildControls, the property would need
to be read-only. If you change that first, does it help at all?

--
Teemu Keiski
AspInsider, ASP.NET MVPhttp://blogs.aspadvice.com/jotekehttp://teemukeiski.net




I am just getting started developing custom user controls, and I am
having issues keep the inner properties of nested controls in sync
with the properties in the designer window. When I change a property
of a nested control in the properties window, the designer does not
automatically redraw itself. If I switch to HTML Mode and then return
to design mode, the control is redrawn. But If I switch back to HTML
Mode the inner properties are not updated.
However, If I change a property of my custom control or the font-bold
property of the nested control in the design window, the nested
control is refreshed and the inner properties are correctly updated.
How do I keep the two in sync? Am I missing something here? Do I
need to implement a TypeConverter and set NotifyParentProperty(True)
to keep the designer in sync with the properties window. If I do, how
can I implement one for web controls as I will have several controls
and do not feel like coding a wrapper for every property of every
control on the page. Or, is there some why to manually fire the event
that is raised when the nested control's font-bold is changed in the
properties window.
Also, what is the difference between refresh.repaint and refresh.all.
Does one only redraw the control on the designer while the other
recreates the controls properties and then redraws the control on the
designer?
Here is my code in the simplest form. Thanks for the help in
advance...
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
<Assembly: TagPrefix("Editor", "cms")>
<ParseChildren(True), Designer("System.Web.UI.Design.ControlDesigner,
System.Design"), DefaultProperty("Text"), ToolboxData("<cms:Editor
runat=server></cms:Editor>"),
RefreshProperties(RefreshProperties.Repaint)> Public Class Editor
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer
Dim _text As String
<Bindable(True), Category("Appearance"), DefaultValue("")>
Property [Text]() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
Private _TitleLabel As Label
<Category("CMS"), Bindable(True),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
RefreshProperties(RefreshProperties.Repaint),
NotifyParentProperty(True),
PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property [TitleLabel]() As Label
Get
Return _TitleLabel
End Get
Set(ByVal Value As Label)
_TitleLabel = Value
Me.ChildControlsCreated = False
Me.EnsureChildControls()
End Set
End Property- Hide quoted text -

- Show quoted text -
 
T

Teemu Keiski

It does work if you call EnsureChildControls() in the getter and then expose
the control, it's standard pattern in exposing complex objects in ASP.NEt
Server Controls. (I'm just right now testing with VS2008)

If there is issue it could be that NotifyParentProperty is not defined on
the Label control at the main class level (and it cannot be since it's
limited to the property).So when something notifiable happens on the
TitleLabel, you should have a parent main prioperty wrapped to the property
of the TitleLabel so that it would work

Anyways the code currently working is:

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls


<Assembly: TagPrefix("Editor", "cms")>
<ParseChildren(True), Designer("System.Web.UI.Design.ControlDesigner,
System.Design"), DefaultProperty("Text"), ToolboxData("<cms:Editor
runat=server></cms:Editor>"), _
RefreshProperties(RefreshProperties.Repaint)> _
Public Class Editor
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer

'Dim _text As String

'<Bindable(True), Category("Appearance"), DefaultValue("")> _
'Property [Text]() As String
' Get
' Return _text
' End Get

' Set(ByVal Value As String)
' _text = Value
' End Set

'End Property

Protected Overrides Sub CreateChildControls()
_TitleLabel = New Label()
Controls.Add(_TitleLabel)
End Sub

Private _TitleLabel As Label
<Category("CMS"), Bindable(True), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), _
RefreshProperties(RefreshProperties.Repaint), _
NotifyParentProperty(True), _
PersistenceMode(PersistenceMode.InnerProperty)> _
Public ReadOnly Property [TitleLabel]() As Label
Get
EnsureChildControls()
Return _TitleLabel
End Get

End Property

End Class


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net




Alexander Higgins said:
Thanks for the suggestion. I tries not understanding the logic, but
in any case it did not help. Making the property readonly prevents
the ability to set its properties at all. I must create the control
during the CreateChildControls events and after that what is set can
not be changed.

I am not trying to do anything complex here, I am simply making a
composite control. I need to offer the developers the ability to
modify the composites child controls via HTML Mode,and with the
properties window in Visual Studio.Net.

I just can't figure out why the property changes on the nested control
do not update globally when the changes are made. Even more
frustrating is in VS 2005 the properties chnages via the property
window are not refelected at all.

One thing that pops up is that if the Label exposed by the TitleLabel
property is actually created in CreateChildControls, the property would
need
to be read-only. If you change that first, does it help at all?

--
Teemu Keiski
AspInsider, ASP.NET
MVPhttp://blogs.aspadvice.com/jotekehttp://teemukeiski.net




I am just getting started developing custom user controls, and I am
having issues keep the inner properties of nested controls in sync
with the properties in the designer window. When I change a property
of a nested control in the properties window, the designer does not
automatically redraw itself. If I switch to HTML Mode and then return
to design mode, the control is redrawn. But If I switch back to HTML
Mode the inner properties are not updated.
However, If I change a property of my custom control or the font-bold
property of the nested control in the design window, the nested
control is refreshed and the inner properties are correctly updated.
How do I keep the two in sync? Am I missing something here? Do I
need to implement a TypeConverter and set NotifyParentProperty(True)
to keep the designer in sync with the properties window. If I do, how
can I implement one for web controls as I will have several controls
and do not feel like coding a wrapper for every property of every
control on the page. Or, is there some why to manually fire the event
that is raised when the nested control's font-bold is changed in the
properties window.
Also, what is the difference between refresh.repaint and refresh.all.
Does one only redraw the control on the designer while the other
recreates the controls properties and then redraws the control on the
designer?
Here is my code in the simplest form. Thanks for the help in
advance...
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
<Assembly: TagPrefix("Editor", "cms")>
<ParseChildren(True), Designer("System.Web.UI.Design.ControlDesigner,
System.Design"), DefaultProperty("Text"), ToolboxData("<cms:Editor
runat=server></cms:Editor>"),
RefreshProperties(RefreshProperties.Repaint)> Public Class Editor
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer
Dim _text As String
<Bindable(True), Category("Appearance"), DefaultValue("")>
Property [Text]() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
Private _TitleLabel As Label
<Category("CMS"), Bindable(True),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
RefreshProperties(RefreshProperties.Repaint),
NotifyParentProperty(True),
PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property [TitleLabel]() As Label
Get
Return _TitleLabel
End Get
Set(ByVal Value As Label)
_TitleLabel = Value
Me.ChildControlsCreated = False
Me.EnsureChildControls()
End Set
End Property- Hide quoted text -

- Show quoted text -
 

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

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top