[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

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

Alexander Higgins

7/21/2007 1:00:00 AM

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

3 Answers

Teemu Keiski

7/22/2007 6:11:00 PM

0

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....
http://teemu...


"Alexander Higgins" <alexhiggins732@hotmail.com> wrote in message
news:1184979597.280413.64640@m3g2000hsh.googlegroups.com...
> 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
>


Alexander Higgins

7/23/2007 2:50:00 PM

0

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.

On Jul 22, 2:11 pm, "Teemu Keiski" <jot...@aspalliance.com> wrote:
> 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://teemu...
>
> "Alexander Higgins" <alexhiggins...@hotmail.com> wrote in message
>
> news:1184979597.280413.64640@m3g2000hsh.googlegroups.com...
>
>
>
> > 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- Hide quoted text -
>
> - Show quoted text -


Teemu Keiski

7/30/2007 9:09:00 PM

0

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....
http://teemu...




"Alexander Higgins" <alexhiggins732@hotmail.com> wrote in message
news:1185202219.471969.14580@r34g2000hsd.googlegroups.com...
> 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.
>
> On Jul 22, 2:11 pm, "Teemu Keiski" <jot...@aspalliance.com> wrote:
>> 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....http://teemu...
>>
>> "Alexander Higgins" <alexhiggins...@hotmail.com> wrote in message
>>
>> news:1184979597.280413.64640@m3g2000hsh.googlegroups.com...
>>
>>
>>
>> > 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- Hide quoted text -
>>
>> - Show quoted text -
>
>