Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Bob Brunton #1
Composite WebControl -- Child Control Property Persistance at Design-time
Hi,
I seen, this asked a number of times at this group but still have not
seen any complete/rectified/fixed code.
I have created a Composite WebControl, Added a button to it and
exposed this child button as a property. But the properties are not
persisting at design-time. Are the Attributes correct? See Code below.
Now I want to add other controls to this, when/if I get it working. So
simply extending the button control is not a valid solution.
I know the response to this will be greatly appreciated by all those
who have tried but failed, asked but were unanwsered.
Thanks for you replies, If you can get this to work .. great Karma
will come your way.
Regards Nick
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace TestWebControls
{
[
ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>"), PersistChildren(false),
ParseChildren(true)]
public class WebCustomControl1 :
System.Web.UI.WebControls.WebControl, INamingContainer
{
private System.Web.UI.WebControls.TextBox _TextBoxStreet ;//= new
System.Web.UI.WebControls.TextBox();
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
public TextBox Street
{
get{
return _TextBoxStreet;
}
}
protected override void OnInit(EventArgs e)
{
EnsureChildControls();
base.OnInit (e);
}
protected override void CreateChildControls()
{
if(_TextBoxStreet == null)
{
_TextBoxStreet = new System.Web.UI.WebControls.TextBox();
this.Controls.Add(_TextBoxStreet);
}
base.CreateChildControls();
}
protected override void Render(HtmlTextWriter output)
{
base.Render(output);
}
}
}
Bob Brunton Guest
-
Custom Web Control Design-Time Property
Hi!! I´m writing a custom control. It´s working OK. I´ve added the Editor atribute to one of it´t properties and it works OK when the property... -
Possible to create a composite control that has a child control that is a validator that validates the composite control itself?
I am attempting to create a composite control which has a label, followed by an optional error message, followed by two text boxes. I have... -
q: 'composite' control: works fine, but no children @ design time ?
Hi All ! I have my control, which populates inner ControlCollection via custom control builder and AddParsedSubObject function. Everything works... -
Composite Control design time behavior
I have created a composite control that combines a Label and a Textbox, where the label appears immediately above the textbox. This seems to work... -
Using Table control in a custom composite control. Control does not render properly in design time.
All, I have written a very simple custom composite control that includes a control of type System.Web.UI.WebControls.Table. The control... -
Bob Brunton #2
Re: Composite WebControl -- Child Control Property Persistance at Design-time
No answer?
If this can't be done then does anyone have a work around?
I thought the dotnet framework could do all. I've followed all the
reference material on webcontrol building and thought this would be
trivial.
If anyone has the answer I will be more than greatfull.
REgards Nick
[email]nickduran@hotmail.com[/email] (Bob Brunton) wrote in message news:<4f8667c2.0402051726.2477ec94@posting.google. com>...> Hi,
>
> I seen, this asked a number of times at this group but still have not
> seen any complete/rectified/fixed code.
>
> I have created a Composite WebControl, Added a button to it and
> exposed this child button as a property. But the properties are not
> persisting at design-time. Are the Attributes correct? See Code below.
>
> Now I want to add other controls to this, when/if I get it working. So
> simply extending the button control is not a valid solution.
>
> I know the response to this will be greatly appreciated by all those
> who have tried but failed, asked but were unanwsered.
>
> Thanks for you replies, If you can get this to work .. great Karma
> will come your way.
>
> Regards Nick
>
> using System;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.ComponentModel;
>
> namespace TestWebControls
> {
>
> [
> ToolboxData("<{0}:WebCustomControl1
> runat=server></{0}:WebCustomControl1>"), PersistChildren(false),
> ParseChildren(true)]
> public class WebCustomControl1 :
> System.Web.UI.WebControls.WebControl, INamingContainer
> {
>
> private System.Web.UI.WebControls.TextBox _TextBoxStreet ;//= new
> System.Web.UI.WebControls.TextBox();
>
> [DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
> PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
> public TextBox Street
> {
> get{
> return _TextBoxStreet;
> }
> }
> protected override void OnInit(EventArgs e)
> {
> EnsureChildControls();
> base.OnInit (e);
> }
>
> protected override void CreateChildControls()
> {
> if(_TextBoxStreet == null)
> {
> _TextBoxStreet = new System.Web.UI.WebControls.TextBox();
> this.Controls.Add(_TextBoxStreet);
> }
> base.CreateChildControls();
> }
>
> protected override void Render(HtmlTextWriter output)
> {
> base.Render(output);
> }
> }
> }Bob Brunton Guest
-
Alessandro Zifiglio #3
Re: Composite WebControl -- Child Control Property Persistance at Design-time
Reposting --hope there is no duplicate. I dont see my previous post ;P
hi Bob, you need to use the textbox controls text property in your get/set
accessors and not supply the control as a whole here. Your textbox control
is persisted already when your adding it to your controls collection. The
CreatechildControls method is fired after postback which reloads your
textbox into the controls collection. This is the only prerequisite for
dynamically added controls to persist their state after postback. I've also
noted that you have supplied the
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)
attribute to your Get accessor property which is useless, use this for
complex types only. PersistenceMode(PersistenceMode.InnerDefaultProper ty)
also is useless here. all you need to do is :
public string Street
{
get{
EnsureChildControls();
return _TextBoxStreet.Text;
set
{
EnsureChildControls();
_TextBoxStreet.Text = value;
}
}
Also note that child controls maintain their own state, and you dont have to
manually add this to viewstate to have it persist. Make sure you remove the
"if conditional statement" you got in CreateChildControls. All childcontrols
you add to the controls collection have to be recreated and your if
statement breaks this
"Bob Brunton" <nickduran@hotmail.com> wrote in message
news:4f8667c2.0402070342.7768e868@posting.google.c om...news:<4f8667c2.0402051726.2477ec94@posting.google. com>...> No answer?
>
> If this can't be done then does anyone have a work around?
> I thought the dotnet framework could do all. I've followed all the
> reference material on webcontrol building and thought this would be
> trivial.
>
> If anyone has the answer I will be more than greatfull.
>
> REgards Nick
>
>
>
> [email]nickduran@hotmail.com[/email] (Bob Brunton) wrote in message[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),> > Hi,
> >
> > I seen, this asked a number of times at this group but still have not
> > seen any complete/rectified/fixed code.
> >
> > I have created a Composite WebControl, Added a button to it and
> > exposed this child button as a property. But the properties are not
> > persisting at design-time. Are the Attributes correct? See Code below.
> >
> > Now I want to add other controls to this, when/if I get it working. So
> > simply extending the button control is not a valid solution.
> >
> > I know the response to this will be greatly appreciated by all those
> > who have tried but failed, asked but were unanwsered.
> >
> > Thanks for you replies, If you can get this to work .. great Karma
> > will come your way.
> >
> > Regards Nick
> >
> > using System;
> > using System.Web.UI;
> > using System.Web.UI.WebControls;
> > using System.ComponentModel;
> >
> > namespace TestWebControls
> > {
> >
> > [
> > ToolboxData("<{0}:WebCustomControl1
> > runat=server></{0}:WebCustomControl1>"), PersistChildren(false),
> > ParseChildren(true)]
> > public class WebCustomControl1 :
> > System.Web.UI.WebControls.WebControl, INamingContainer
> > {
> >
> > private System.Web.UI.WebControls.TextBox _TextBoxStreet ;//= new
> > System.Web.UI.WebControls.TextBox();
> >
> >> > PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
> > public TextBox Street
> > {
> > get{
> > return _TextBoxStreet;
> > }
> > }
> > protected override void OnInit(EventArgs e)
> > {
> > EnsureChildControls();
> > base.OnInit (e);
> > }
> >
> > protected override void CreateChildControls()
> > {
> > if(_TextBoxStreet == null)
> > {
> > _TextBoxStreet = new System.Web.UI.WebControls.TextBox();
> > this.Controls.Add(_TextBoxStreet);
> > }
> > base.CreateChildControls();
> > }
> >
> > protected override void Render(HtmlTextWriter output)
> > {
> > base.Render(output);
> > }
> > }
> > }
Alessandro Zifiglio Guest
-
Bob Brunton #4
Re: Composite WebControl -- Child Control Property Persistance at Design-time
Thanks for the reply Alessandro,
But I actually want to expose the TextBox as a public property, so I
do need the attributes for this complex type (TextBox). I want more
than just the TextBox Text property.
Nick
"Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote in message news:<vH5Vb.4518$HO2.2345@news.edisontel.com>...> Reposting --hope there is no duplicate. I dont see my previous post ;P
>
> hi Bob, you need to use the textbox controls text property in your get/set
> accessors and not supply the control as a whole here. Your textbox control
> is persisted already when your adding it to your controls collection. The
> CreatechildControls method is fired after postback which reloads your
> textbox into the controls collection. This is the only prerequisite for
> dynamically added controls to persist their state after postback. I've also
> noted that you have supplied the
> DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)
> attribute to your Get accessor property which is useless, use this for
> complex types only. PersistenceMode(PersistenceMode.InnerDefaultProper ty)
> also is useless here. all you need to do is :
>
> public string Street
> {
> get{
> EnsureChildControls();
> return _TextBoxStreet.Text;
> set
> {
> EnsureChildControls();
> _TextBoxStreet.Text = value;
> }
> }
>
> Also note that child controls maintain their own state, and you dont have to
> manually add this to viewstate to have it persist. Make sure you remove the
> "if conditional statement" you got in CreateChildControls. All childcontrols
> you add to the controls collection have to be recreated and your if
> statement breaks this
> "Bob Brunton" <nickduran@hotmail.com> wrote in message
> news:4f8667c2.0402070342.7768e868@posting.google.c om...> news:<4f8667c2.0402051726.2477ec94@posting.google. com>...> > No answer?
> >
> > If this can't be done then does anyone have a work around?
> > I thought the dotnet framework could do all. I've followed all the
> > reference material on webcontrol building and thought this would be
> > trivial.
> >
> > If anyone has the answer I will be more than greatfull.
> >
> > REgards Nick
> >
> >
> >
> > [email]nickduran@hotmail.com[/email] (Bob Brunton) wrote in message> [DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),> > > Hi,
> > >
> > > I seen, this asked a number of times at this group but still have not
> > > seen any complete/rectified/fixed code.
> > >
> > > I have created a Composite WebControl, Added a button to it and
> > > exposed this child button as a property. But the properties are not
> > > persisting at design-time. Are the Attributes correct? See Code below.
> > >
> > > Now I want to add other controls to this, when/if I get it working. So
> > > simply extending the button control is not a valid solution.
> > >
> > > I know the response to this will be greatly appreciated by all those
> > > who have tried but failed, asked but were unanwsered.
> > >
> > > Thanks for you replies, If you can get this to work .. great Karma
> > > will come your way.
> > >
> > > Regards Nick
> > >
> > > using System;
> > > using System.Web.UI;
> > > using System.Web.UI.WebControls;
> > > using System.ComponentModel;
> > >
> > > namespace TestWebControls
> > > {
> > >
> > > [
> > > ToolboxData("<{0}:WebCustomControl1
> > > runat=server></{0}:WebCustomControl1>"), PersistChildren(false),
> > > ParseChildren(true)]
> > > public class WebCustomControl1 :
> > > System.Web.UI.WebControls.WebControl, INamingContainer
> > > {
> > >
> > > private System.Web.UI.WebControls.TextBox _TextBoxStreet ;//= new
> > > System.Web.UI.WebControls.TextBox();
> > >
> > >> base.CreateChildControls();> > > PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
> > > public TextBox Street
> > > {
> > > get{
> > > return _TextBoxStreet;
> > > }
> > > }
> > > protected override void OnInit(EventArgs e)
> > > {
> > > EnsureChildControls();
> > > base.OnInit (e);
> > > }
> > >
> > > protected override void CreateChildControls()
> > > {
> > > if(_TextBoxStreet == null)
> > > {
> > > _TextBoxStreet = new System.Web.UI.WebControls.TextBox();
> > > this.Controls.Add(_TextBoxStreet);
> > > }> > > }
> > >
> > > protected override void Render(HtmlTextWriter output)
> > > {
> > > base.Render(output);
> > > }
> > > }
> > > }Bob Brunton Guest
-
Alessandro Zifiglio #5
Re: Composite WebControl -- Child Control Property Persistance at Design-time
Now i see where you are getting at. Simply trying out your sample code does
not persist the data like you stated. I have tried Customizing State
Restoration with ViewState by overriding saveviewstate, loadviewstate and
trackviewstate but this didnt make a difference. I'll put in some time later
this evening and post how far i were able to get ;P
"Bob Brunton" <nickduran@hotmail.com> wrote in message
news:4f8667c2.0402081245.49c99a33@posting.google.c om...message news:<vH5Vb.4518$HO2.2345@news.edisontel.com>...> Thanks for the reply Alessandro,
>
> But I actually want to expose the TextBox as a public property, so I
> do need the attributes for this complex type (TextBox). I want more
> than just the TextBox Text property.
>
> Nick
>
>
>
> "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote inget/set> > Reposting --hope there is no duplicate. I dont see my previous post ;P
> >
> > hi Bob, you need to use the textbox controls text property in yourcontrol> > accessors and not supply the control as a whole here. Your textboxThe> > is persisted already when your adding it to your controls collection.also> > CreatechildControls method is fired after postback which reloads your
> > textbox into the controls collection. This is the only prerequisite for
> > dynamically added controls to persist their state after postback. I'vePersistenceMode(PersistenceMode.InnerDefaultProper ty)> > noted that you have supplied the
> > DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)
> > attribute to your Get accessor property which is useless, use this for
> > complex types only.have to> > also is useless here. all you need to do is :
> >
> > public string Street
> > {
> > get{
> > EnsureChildControls();
> > return _TextBoxStreet.Text;
> > set
> > {
> > EnsureChildControls();
> > _TextBoxStreet.Text = value;
> > }
> > }
> >
> > Also note that child controls maintain their own state, and you dontthe> > manually add this to viewstate to have it persist. Make sure you removechildcontrols> > "if conditional statement" you got in CreateChildControls. Allnot> > you add to the controls collection have to be recreated and your if
> > statement breaks this
> > "Bob Brunton" <nickduran@hotmail.com> wrote in message
> > news:4f8667c2.0402070342.7768e868@posting.google.c om...> > news:<4f8667c2.0402051726.2477ec94@posting.google. com>...> > > No answer?
> > >
> > > If this can't be done then does anyone have a work around?
> > > I thought the dotnet framework could do all. I've followed all the
> > > reference material on webcontrol building and thought this would be
> > > trivial.
> > >
> > > If anyone has the answer I will be more than greatfull.
> > >
> > > REgards Nick
> > >
> > >
> > >
> > > [email]nickduran@hotmail.com[/email] (Bob Brunton) wrote in message> > > > Hi,
> > > >
> > > > I seen, this asked a number of times at this group but still havebelow.> > > > seen any complete/rectified/fixed code.
> > > >
> > > > I have created a Composite WebControl, Added a button to it and
> > > > exposed this child button as a property. But the properties are not
> > > > persisting at design-time. Are the Attributes correct? See CodeSo> > > >
> > > > Now I want to add other controls to this, when/if I get it working.[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),> >> > > > simply extending the button control is not a valid solution.
> > > >
> > > > I know the response to this will be greatly appreciated by all those
> > > > who have tried but failed, asked but were unanwsered.
> > > >
> > > > Thanks for you replies, If you can get this to work .. great Karma
> > > > will come your way.
> > > >
> > > > Regards Nick
> > > >
> > > > using System;
> > > > using System.Web.UI;
> > > > using System.Web.UI.WebControls;
> > > > using System.ComponentModel;
> > > >
> > > > namespace TestWebControls
> > > > {
> > > >
> > > > [
> > > > ToolboxData("<{0}:WebCustomControl1
> > > > runat=server></{0}:WebCustomControl1>"), PersistChildren(false),
> > > > ParseChildren(true)]
> > > > public class WebCustomControl1 :
> > > > System.Web.UI.WebControls.WebControl, INamingContainer
> > > > {
> > > >
> > > > private System.Web.UI.WebControls.TextBox _TextBoxStreet ;//= new
> > > > System.Web.UI.WebControls.TextBox();
> > > >
> > > >> > base.CreateChildControls();> > > > PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
> > > > public TextBox Street
> > > > {
> > > > get{
> > > > return _TextBoxStreet;
> > > > }
> > > > }
> > > > protected override void OnInit(EventArgs e)
> > > > {
> > > > EnsureChildControls();
> > > > base.OnInit (e);
> > > > }
> > > >
> > > > protected override void CreateChildControls()
> > > > {
> > > > if(_TextBoxStreet == null)
> > > > {
> > > > _TextBoxStreet = new System.Web.UI.WebControls.TextBox();
> > > > this.Controls.Add(_TextBoxStreet);
> > > > }> > > > }
> > > >
> > > > protected override void Render(HtmlTextWriter output)
> > > > {
> > > > base.Render(output);
> > > > }
> > > > }
> > > > }
Alessandro Zifiglio Guest
-
Alessandro Zifiglio #6
Re: Composite WebControl -- Child Control Property Persistance at Design-time
This is all actually working without the need to resort to manually adding
the items to viewstate etc. However you get awkward behavior. Awkward
behavoir being that, in vs.net designer the values wont get added to the
page until you set another property in the container. For example first set
the properties for your textbox, that is select some styling, add some text
to its text property and if you went into html view you wont see these
values as you expect them to be. However if you set another property from
the container that is not part of the textbox, only then are the values for
your textbox control reflected in html view and saved in the page. Now if
you went back to look you will notice this change. For the rest it all works
as expected. If you set any values at runtime in code, the values is
persisted during postback.
I had ran a small test earlier today and never got to see the textbox in the
designer and thought this werent working and went about Customizing State
Restoration and overriding saveviewstate --loadviewstate --trackviewstate
uselessly ;P
Now I see the textbox in the designer by associating a custom designer class
to the control as you will note in the example code i am pasting.
If the only problem is your wanting the values immidiately shown in html
view that is in xml form, which is the expected behavour, then I have no
idea why this is not taking place. Actually i have been stuck here myself
sometime back with a few complex types of my own when associating it with a
custom editor and i worked around dropping my editor as a whole.
I really hope someone from MS is reading this post and sheds some light
here, besides that I will go on thinking that this is a bug in the vs.net
designer. I'm pasting the complete code i have used to test this behavior.
'Code for WebCustomControl1.vb
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Namespace CustomControls
<DefaultProperty("textbox2"), _
Designer(GetType(CustomControls.Design.SimpleDesig ner)), _
ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>")> _
Public Class WebCustomControl1
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer
Private _textbox2 As TextBox
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content), _
PersistenceMode(PersistenceMode.InnerProperty), _
Bindable(True), Category("Appearance"), DefaultValue("")> _
Public Property textbox2() As TextBox
Get
If _textbox2 Is Nothing Then
_textbox2 = New TextBox()
End If
Return _textbox2
End Get
Set(ByVal Value As TextBox)
_textbox2 = Value
End Set
End Property
Friend Sub createControlsHierarchy()
Controls.Clear()
Controls.Add(New LiteralControl("<br /><br /><br /><h3>The text
box: : </h3>"))
Controls.Add(textbox2)
ChildControlsCreated = True
End Sub
Protected Overrides Sub CreateChildControls()
createControlsHierarchy()
End Sub
End Class
End Namespace
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
'code for SimpleDesigner.vb
Imports System
Imports System.IO
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.WebControls
Namespace CustomControls.Design
Public Class SimpleDesigner
Inherits System.Web.UI.Design.ControlDesigner
Public Overrides Function GetDesignTimeHtml() As String
' Component is the instance of the component or control that
' this designer object is associated with. This property is
' inherited from System.ComponentModel.ComponentDesigner.
Dim designTimeHTML As String
Dim Instance As WebCustomControl1 = CType(Component,
WebCustomControl1)
If Not Instance.textbox2 Is Nothing Then
Instance.createControlsHierarchy()
designTimeHTML = MyBase.GetDesignTimeHtml
Return designTimeHTML
Else
Return GetEmptyDesignTimeHtml()
End If
End Function
End Class
End Namespace
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
'code for webform1.aspx
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<cc1:WebCustomControl1 id="WebCustomControl11" style="Z-INDEX: 101; LEFT:
335px; POSITION: absolute; TOP: 224px" runat="server" BackColor="#E0E0E0"
Width="158px">
<textbox2 BackColor="#C0C000" ID="textbox1">
Moi TextBox
</textbox2>
</cc1:WebCustomControl1>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 294px; POSITION:
absolute; TOP: 86px" runat="server" Text="Button"></asp:Button>
</form>
</body>
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
'code for webform1.vb
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
WebCustomControl11.textbox2.Text = "Viewstate Working"
End If
End Sub
"Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote in
message news:4sNVb.5243$HO2.1647@news.edisontel.com...does> Now i see where you are getting at. Simply trying out your sample codelater> not persist the data like you stated. I have tried Customizing State
> Restoration with ViewState by overriding saveviewstate, loadviewstate and
> trackviewstate but this didnt make a difference. I'll put in some timefor> this evening and post how far i were able to get ;P
>
>
> "Bob Brunton" <nickduran@hotmail.com> wrote in message
> news:4f8667c2.0402081245.49c99a33@posting.google.c om...> message news:<vH5Vb.4518$HO2.2345@news.edisontel.com>...> > Thanks for the reply Alessandro,
> >
> > But I actually want to expose the TextBox as a public property, so I
> > do need the attributes for this complex type (TextBox). I want more
> > than just the TextBox Text property.
> >
> > Nick
> >
> >
> >
> > "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote in> get/set> > > Reposting --hope there is no duplicate. I dont see my previous post ;P
> > >
> > > hi Bob, you need to use the textbox controls text property in your> control> > > accessors and not supply the control as a whole here. Your textbox> The> > > is persisted already when your adding it to your controls collection.> > > CreatechildControls method is fired after postback which reloads your
> > > textbox into the controls collection. This is the only prerequisiteDesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)> also> > > dynamically added controls to persist their state after postback. I've> > > noted that you have supplied the
> > >remove> PersistenceMode(PersistenceMode.InnerDefaultProper ty)> > > attribute to your Get accessor property which is useless, use this for
> > > complex types only.> have to> > > also is useless here. all you need to do is :
> > >
> > > public string Street
> > > {
> > > get{
> > > EnsureChildControls();
> > > return _TextBoxStreet.Text;
> > > set
> > > {
> > > EnsureChildControls();
> > > _TextBoxStreet.Text = value;
> > > }
> > > }
> > >
> > > Also note that child controls maintain their own state, and you dont> > > manually add this to viewstate to have it persist. Make sure younot> the> childcontrols> > > "if conditional statement" you got in CreateChildControls. All> not> > > you add to the controls collection have to be recreated and your if
> > > statement breaks this
> > > "Bob Brunton" <nickduran@hotmail.com> wrote in message
> > > news:4f8667c2.0402070342.7768e868@posting.google.c om...
> > > > No answer?
> > > >
> > > > If this can't be done then does anyone have a work around?
> > > > I thought the dotnet framework could do all. I've followed all the
> > > > reference material on webcontrol building and thought this would be
> > > > trivial.
> > > >
> > > > If anyone has the answer I will be more than greatfull.
> > > >
> > > > REgards Nick
> > > >
> > > >
> > > >
> > > > [email]nickduran@hotmail.com[/email] (Bob Brunton) wrote in message
> > > news:<4f8667c2.0402051726.2477ec94@posting.google. com>...
> > > > > Hi,
> > > > >
> > > > > I seen, this asked a number of times at this group but still have> > > > > seen any complete/rectified/fixed code.
> > > > >
> > > > > I have created a Composite WebControl, Added a button to it and
> > > > > exposed this child button as a property. But the properties areworking.> below.> > > > > persisting at design-time. Are the Attributes correct? See Code> > > > >
> > > > > Now I want to add other controls to this, when/if I get itthose> So> > > > > simply extending the button control is not a valid solution.
> > > > >
> > > > > I know the response to this will be greatly appreciated by all> [DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),> > > > > who have tried but failed, asked but were unanwsered.
> > > > >
> > > > > Thanks for you replies, If you can get this to work .. great Karma
> > > > > will come your way.
> > > > >
> > > > > Regards Nick
> > > > >
> > > > > using System;
> > > > > using System.Web.UI;
> > > > > using System.Web.UI.WebControls;
> > > > > using System.ComponentModel;
> > > > >
> > > > > namespace TestWebControls
> > > > > {
> > > > >
> > > > > [
> > > > > ToolboxData("<{0}:WebCustomControl1
> > > > > runat=server></{0}:WebCustomControl1>"), PersistChildren(false),
> > > > > ParseChildren(true)]
> > > > > public class WebCustomControl1 :
> > > > > System.Web.UI.WebControls.WebControl, INamingContainer
> > > > > {
> > > > >
> > > > > private System.Web.UI.WebControls.TextBox _TextBoxStreet ;//= new
> > > > > System.Web.UI.WebControls.TextBox();
> > > > >
> > > > >
> > >>> > > > > PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
> > > > > public TextBox Street
> > > > > {
> > > > > get{
> > > > > return _TextBoxStreet;
> > > > > }
> > > > > }
> > > > > protected override void OnInit(EventArgs e)
> > > > > {
> > > > > EnsureChildControls();
> > > > > base.OnInit (e);
> > > > > }
> > > > >
> > > > > protected override void CreateChildControls()
> > > > > {
> > > > > if(_TextBoxStreet == null)
> > > > > {
> > > > > _TextBoxStreet = new System.Web.UI.WebControls.TextBox();
> > > > > this.Controls.Add(_TextBoxStreet);
> > > > > }
> > > base.CreateChildControls();
> > > > > }
> > > > >
> > > > > protected override void Render(HtmlTextWriter output)
> > > > > {
> > > > > base.Render(output);
> > > > > }
> > > > > }
> > > > > }
>
Alessandro Zifiglio Guest
-
Bob Brunton #7
Re: Composite WebControl -- Child Control Property Persistance at Design-time
Thanks for your time and effort Alessandro.
I've spent a couple of days on this one, it's driving me nuts. I would
truely appreciate one of the MS team responding, just to get some
closure.
Regards Nick Harrow (alia Bob Brunton)
"Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote in message news:<G6TVb.5340$HO2.2373@news.edisontel.com>...> This is all actually working without the need to resort to manually adding
> the items to viewstate etc. However you get awkward behavior. Awkward
> behavoir being that, in vs.net designer the values wont get added to the
> page until you set another property in the container. For example first set
> the properties for your textbox, that is select some styling, add some text
> to its text property and if you went into html view you wont see these
> values as you expect them to be. However if you set another property from
> the container that is not part of the textbox, only then are the values for
> your textbox control reflected in html view and saved in the page. Now if
> you went back to look you will notice this change. For the rest it all works
> as expected. If you set any values at runtime in code, the values is
> persisted during postback.
>
> I had ran a small test earlier today and never got to see the textbox in the
> designer and thought this werent working and went about Customizing State
> Restoration and overriding saveviewstate --loadviewstate --trackviewstate
> uselessly ;P
>
> Now I see the textbox in the designer by associating a custom designer class
> to the control as you will note in the example code i am pasting.
>
> If the only problem is your wanting the values immidiately shown in html
> view that is in xml form, which is the expected behavour, then I have no
> idea why this is not taking place. Actually i have been stuck here myself
> sometime back with a few complex types of my own when associating it with a
> custom editor and i worked around dropping my editor as a whole.
>
> I really hope someone from MS is reading this post and sheds some light
> here, besides that I will go on thinking that this is a bug in the vs.net
> designer. I'm pasting the complete code i have used to test this behavior.
>
>
>
> 'Code for WebCustomControl1.vb
>
> Imports System.Web.UI
> Imports System.Web.UI.WebControls
> Imports System.ComponentModel
> Namespace CustomControls
> <DefaultProperty("textbox2"), _
> Designer(GetType(CustomControls.Design.SimpleDesig ner)), _
> ToolboxData("<{0}:WebCustomControl1
> runat=server></{0}:WebCustomControl1>")> _
> Public Class WebCustomControl1
> Inherits System.Web.UI.WebControls.WebControl
> Implements INamingContainer
> Private _textbox2 As TextBox
>
>
>
> <DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content), _
> PersistenceMode(PersistenceMode.InnerProperty), _
> Bindable(True), Category("Appearance"), DefaultValue("")> _
> Public Property textbox2() As TextBox
> Get
> If _textbox2 Is Nothing Then
> _textbox2 = New TextBox()
> End If
> Return _textbox2
> End Get
> Set(ByVal Value As TextBox)
> _textbox2 = Value
> End Set
> End Property
> Friend Sub createControlsHierarchy()
> Controls.Clear()
> Controls.Add(New LiteralControl("<br /><br /><br /><h3>The text
> box: : </h3>"))
> Controls.Add(textbox2)
> ChildControlsCreated = True
> End Sub
> Protected Overrides Sub CreateChildControls()
>
> createControlsHierarchy()
>
> End Sub
> End Class
> End Namespace
>
> '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
>
> 'code for SimpleDesigner.vb
>
> Imports System
> Imports System.IO
> Imports System.Web
> Imports System.Web.UI
> Imports System.Web.UI.Design
> Imports System.Web.UI.WebControls
>
> Namespace CustomControls.Design
> Public Class SimpleDesigner
> Inherits System.Web.UI.Design.ControlDesigner
>
>
> Public Overrides Function GetDesignTimeHtml() As String
> ' Component is the instance of the component or control that
> ' this designer object is associated with. This property is
> ' inherited from System.ComponentModel.ComponentDesigner.
> Dim designTimeHTML As String
> Dim Instance As WebCustomControl1 = CType(Component,
> WebCustomControl1)
>
> If Not Instance.textbox2 Is Nothing Then
> Instance.createControlsHierarchy()
> designTimeHTML = MyBase.GetDesignTimeHtml
> Return designTimeHTML
> Else
> Return GetEmptyDesignTimeHtml()
> End If
> End Function
> End Class
> End Namespace
>
> '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
>
> 'code for webform1.aspx
>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> <cc1:WebCustomControl1 id="WebCustomControl11" style="Z-INDEX: 101; LEFT:
> 335px; POSITION: absolute; TOP: 224px" runat="server" BackColor="#E0E0E0"
> Width="158px">
> <textbox2 BackColor="#C0C000" ID="textbox1">
> Moi TextBox
> </textbox2>
> </cc1:WebCustomControl1>
> <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 294px; POSITION:
> absolute; TOP: 86px" runat="server" Text="Button"></asp:Button>
> </form>
> </body>
>
> '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
> 'code for webform1.vb
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> If Not IsPostBack Then
> WebCustomControl11.textbox2.Text = "Viewstate Working"
> End If
> End Sub
> "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote in
> message news:4sNVb.5243$HO2.1647@news.edisontel.com...> does> > Now i see where you are getting at. Simply trying out your sample code> later> > not persist the data like you stated. I have tried Customizing State
> > Restoration with ViewState by overriding saveviewstate, loadviewstate and
> > trackviewstate but this didnt make a difference. I'll put in some time> message news:<vH5Vb.4518$HO2.2345@news.edisontel.com>...> > this evening and post how far i were able to get ;P
> >
> >
> > "Bob Brunton" <nickduran@hotmail.com> wrote in message
> > news:4f8667c2.0402081245.49c99a33@posting.google.c om...> > > Thanks for the reply Alessandro,
> > >
> > > But I actually want to expose the TextBox as a public property, so I
> > > do need the attributes for this complex type (TextBox). I want more
> > > than just the TextBox Text property.
> > >
> > > Nick
> > >
> > >
> > >
> > > "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote in> get/set> > > > Reposting --hope there is no duplicate. I dont see my previous post ;P
> > > >
> > > > hi Bob, you need to use the textbox controls text property in your> control> > > > accessors and not supply the control as a whole here. Your textbox> The> > > > is persisted already when your adding it to your controls collection.> for> > > > CreatechildControls method is fired after postback which reloads your
> > > > textbox into the controls collection. This is the only prerequisite> also> > > > dynamically added controls to persist their state after postback. I've> DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)> > > > noted that you have supplied the
> > > >> PersistenceMode(PersistenceMode.InnerDefaultProper ty)> > > > attribute to your Get accessor property which is useless, use this for
> > > > complex types only.> have to> > > > also is useless here. all you need to do is :
> > > >
> > > > public string Street
> > > > {
> > > > get{
> > > > EnsureChildControls();
> > > > return _TextBoxStreet.Text;
> > > > set
> > > > {
> > > > EnsureChildControls();
> > > > _TextBoxStreet.Text = value;
> > > > }
> > > > }
> > > >
> > > > Also note that child controls maintain their own state, and you dont> remove> > > > manually add this to viewstate to have it persist. Make sure you
> the> childcontrols> > > > "if conditional statement" you got in CreateChildControls. All> news:<4f8667c2.0402051726.2477ec94@posting.google. com>...> > > > you add to the controls collection have to be recreated and your if
> > > > statement breaks this
> > > > "Bob Brunton" <nickduran@hotmail.com> wrote in message
> > > > news:4f8667c2.0402070342.7768e868@posting.google.c om...
> > > > > No answer?
> > > > >
> > > > > If this can't be done then does anyone have a work around?
> > > > > I thought the dotnet framework could do all. I've followed all the
> > > > > reference material on webcontrol building and thought this would be
> > > > > trivial.
> > > > >
> > > > > If anyone has the answer I will be more than greatfull.
> > > > >
> > > > > REgards Nick
> > > > >
> > > > >
> > > > >
> > > > > [email]nickduran@hotmail.com[/email] (Bob Brunton) wrote in message> not> > > > > > Hi,
> > > > > >
> > > > > > I seen, this asked a number of times at this group but still have> not> > > > > > seen any complete/rectified/fixed code.
> > > > > >
> > > > > > I have created a Composite WebControl, Added a button to it and
> > > > > > exposed this child button as a property. But the properties are> below.> > > > > > persisting at design-time. Are the Attributes correct? See Code> working.> > > > > >
> > > > > > Now I want to add other controls to this, when/if I get it
> So> those> > > > > > simply extending the button control is not a valid solution.
> > > > > >
> > > > > > I know the response to this will be greatly appreciated by all> [DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),> > > > > > who have tried but failed, asked but were unanwsered.
> > > > > >
> > > > > > Thanks for you replies, If you can get this to work .. great Karma
> > > > > > will come your way.
> > > > > >
> > > > > > Regards Nick
> > > > > >
> > > > > > using System;
> > > > > > using System.Web.UI;
> > > > > > using System.Web.UI.WebControls;
> > > > > > using System.ComponentModel;
> > > > > >
> > > > > > namespace TestWebControls
> > > > > > {
> > > > > >
> > > > > > [
> > > > > > ToolboxData("<{0}:WebCustomControl1
> > > > > > runat=server></{0}:WebCustomControl1>"), PersistChildren(false),
> > > > > > ParseChildren(true)]
> > > > > > public class WebCustomControl1 :
> > > > > > System.Web.UI.WebControls.WebControl, INamingContainer
> > > > > > {
> > > > > >
> > > > > > private System.Web.UI.WebControls.TextBox _TextBoxStreet ;//= new
> > > > > > System.Web.UI.WebControls.TextBox();
> > > > > >
> > > > > >
> > > >> base.CreateChildControls();> > > > > > PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
> > > > > > public TextBox Street
> > > > > > {
> > > > > > get{
> > > > > > return _TextBoxStreet;
> > > > > > }
> > > > > > }
> > > > > > protected override void OnInit(EventArgs e)
> > > > > > {
> > > > > > EnsureChildControls();
> > > > > > base.OnInit (e);
> > > > > > }
> > > > > >
> > > > > > protected override void CreateChildControls()
> > > > > > {
> > > > > > if(_TextBoxStreet == null)
> > > > > > {
> > > > > > _TextBoxStreet = new System.Web.UI.WebControls.TextBox();
> > > > > > this.Controls.Add(_TextBoxStreet);
> > > > > > }> >> > > > > > }
> > > > > >
> > > > > > protected override void Render(HtmlTextWriter output)
> > > > > > {
> > > > > > base.Render(output);
> > > > > > }
> > > > > > }
> > > > > > }
> >Bob Brunton Guest
-
Bob Brunton #8
Re: Composite WebControl -- Child Control Property Persistance at Design-time
Still no response from microsoft?
I will understand if there is a good reason why other controls can't
be exposed as public properties in a composite control. But I can't
work it out.
I have applied all the attributes.
I have included full source code at the beginning of this thread.
[email]nickduran@hotmail.com[/email] (Bob Brunton) wrote in message news:<4f8667c2.0402092022.3b526942@posting.google. com>...> Thanks for your time and effort Alessandro.
>
> I've spent a couple of days on this one, it's driving me nuts. I would
> truely appreciate one of the MS team responding, just to get some
> closure.
>
> Regards Nick Harrow (alia Bob Brunton)
>
>
> "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote in message news:<G6TVb.5340$HO2.2373@news.edisontel.com>...> does> > This is all actually working without the need to resort to manually adding
> > the items to viewstate etc. However you get awkward behavior. Awkward
> > behavoir being that, in vs.net designer the values wont get added to the
> > page until you set another property in the container. For example first set
> > the properties for your textbox, that is select some styling, add some text
> > to its text property and if you went into html view you wont see these
> > values as you expect them to be. However if you set another property from
> > the container that is not part of the textbox, only then are the values for
> > your textbox control reflected in html view and saved in the page. Now if
> > you went back to look you will notice this change. For the rest it all works
> > as expected. If you set any values at runtime in code, the values is
> > persisted during postback.
> >
> > I had ran a small test earlier today and never got to see the textbox in the
> > designer and thought this werent working and went about Customizing State
> > Restoration and overriding saveviewstate --loadviewstate --trackviewstate
> > uselessly ;P
> >
> > Now I see the textbox in the designer by associating a custom designer class
> > to the control as you will note in the example code i am pasting.
> >
> > If the only problem is your wanting the values immidiately shown in html
> > view that is in xml form, which is the expected behavour, then I have no
> > idea why this is not taking place. Actually i have been stuck here myself
> > sometime back with a few complex types of my own when associating it with a
> > custom editor and i worked around dropping my editor as a whole.
> >
> > I really hope someone from MS is reading this post and sheds some light
> > here, besides that I will go on thinking that this is a bug in the vs.net
> > designer. I'm pasting the complete code i have used to test this behavior.
> >
> >
> >
> > 'Code for WebCustomControl1.vb
> >
> > Imports System.Web.UI
> > Imports System.Web.UI.WebControls
> > Imports System.ComponentModel
> > Namespace CustomControls
> > <DefaultProperty("textbox2"), _
> > Designer(GetType(CustomControls.Design.SimpleDesig ner)), _
> > ToolboxData("<{0}:WebCustomControl1
> > runat=server></{0}:WebCustomControl1>")> _
> > Public Class WebCustomControl1
> > Inherits System.Web.UI.WebControls.WebControl
> > Implements INamingContainer
> > Private _textbox2 As TextBox
> >
> >
> >
> > <DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content), _
> > PersistenceMode(PersistenceMode.InnerProperty), _
> > Bindable(True), Category("Appearance"), DefaultValue("")> _
> > Public Property textbox2() As TextBox
> > Get
> > If _textbox2 Is Nothing Then
> > _textbox2 = New TextBox()
> > End If
> > Return _textbox2
> > End Get
> > Set(ByVal Value As TextBox)
> > _textbox2 = Value
> > End Set
> > End Property
> > Friend Sub createControlsHierarchy()
> > Controls.Clear()
> > Controls.Add(New LiteralControl("<br /><br /><br /><h3>The text
> > box: : </h3>"))
> > Controls.Add(textbox2)
> > ChildControlsCreated = True
> > End Sub
> > Protected Overrides Sub CreateChildControls()
> >
> > createControlsHierarchy()
> >
> > End Sub
> > End Class
> > End Namespace
> >
> > '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
> >
> > 'code for SimpleDesigner.vb
> >
> > Imports System
> > Imports System.IO
> > Imports System.Web
> > Imports System.Web.UI
> > Imports System.Web.UI.Design
> > Imports System.Web.UI.WebControls
> >
> > Namespace CustomControls.Design
> > Public Class SimpleDesigner
> > Inherits System.Web.UI.Design.ControlDesigner
> >
> >
> > Public Overrides Function GetDesignTimeHtml() As String
> > ' Component is the instance of the component or control that
> > ' this designer object is associated with. This property is
> > ' inherited from System.ComponentModel.ComponentDesigner.
> > Dim designTimeHTML As String
> > Dim Instance As WebCustomControl1 = CType(Component,
> > WebCustomControl1)
> >
> > If Not Instance.textbox2 Is Nothing Then
> > Instance.createControlsHierarchy()
> > designTimeHTML = MyBase.GetDesignTimeHtml
> > Return designTimeHTML
> > Else
> > Return GetEmptyDesignTimeHtml()
> > End If
> > End Function
> > End Class
> > End Namespace
> >
> > '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
> >
> > 'code for webform1.aspx
> >
> > <body MS_POSITIONING="GridLayout">
> > <form id="Form1" method="post" runat="server">
> > <cc1:WebCustomControl1 id="WebCustomControl11" style="Z-INDEX: 101; LEFT:
> > 335px; POSITION: absolute; TOP: 224px" runat="server" BackColor="#E0E0E0"
> > Width="158px">
> > <textbox2 BackColor="#C0C000" ID="textbox1">
> > Moi TextBox
> > </textbox2>
> > </cc1:WebCustomControl1>
> > <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 294px; POSITION:
> > absolute; TOP: 86px" runat="server" Text="Button"></asp:Button>
> > </form>
> > </body>
> >
> > '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
> > 'code for webform1.vb
> >
> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles MyBase.Load
> > If Not IsPostBack Then
> > WebCustomControl11.textbox2.Text = "Viewstate Working"
> > End If
> > End Sub
> > "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote in
> > message news:4sNVb.5243$HO2.1647@news.edisontel.com...> > > Now i see where you are getting at. Simply trying out your sample code> later> > > not persist the data like you stated. I have tried Customizing State
> > > Restoration with ViewState by overriding saveviewstate, loadviewstate and
> > > trackviewstate but this didnt make a difference. I'll put in some time> message news:<vH5Vb.4518$HO2.2345@news.edisontel.com>...> > > this evening and post how far i were able to get ;P
> > >
> > >
> > > "Bob Brunton" <nickduran@hotmail.com> wrote in message
> > > news:4f8667c2.0402081245.49c99a33@posting.google.c om...
> > > > Thanks for the reply Alessandro,
> > > >
> > > > But I actually want to expose the TextBox as a public property, so I
> > > > do need the attributes for this complex type (TextBox). I want more
> > > > than just the TextBox Text property.
> > > >
> > > > Nick
> > > >
> > > >
> > > >
> > > > "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote in> get/set> > > > > Reposting --hope there is no duplicate. I dont see my previous post ;P
> > > > >
> > > > > hi Bob, you need to use the textbox controls text property in your> control> > > > > accessors and not supply the control as a whole here. Your textbox> The> > > > > is persisted already when your adding it to your controls collection.> for> > > > > CreatechildControls method is fired after postback which reloads your
> > > > > textbox into the controls collection. This is the only prerequisite> also> > > > > dynamically added controls to persist their state after postback. I've> DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)> > > > > noted that you have supplied the
> > > > >> PersistenceMode(PersistenceMode.InnerDefaultProper ty)> > > > > attribute to your Get accessor property which is useless, use this for
> > > > > complex types only.> have to> > > > > also is useless here. all you need to do is :
> > > > >
> > > > > public string Street
> > > > > {
> > > > > get{
> > > > > EnsureChildControls();
> > > > > return _TextBoxStreet.Text;
> > > > > set
> > > > > {
> > > > > EnsureChildControls();
> > > > > _TextBoxStreet.Text = value;
> > > > > }
> > > > > }
> > > > >
> > > > > Also note that child controls maintain their own state, and you dont> childcontrols> > remove> > > > > manually add this to viewstate to have it persist. Make sure you
> > the> > > > > "if conditional statement" you got in CreateChildControls. All> news:<4f8667c2.0402051726.2477ec94@posting.google. com>...> > > > > you add to the controls collection have to be recreated and your if
> > > > > statement breaks this
> > > > > "Bob Brunton" <nickduran@hotmail.com> wrote in message
> > > > > news:4f8667c2.0402070342.7768e868@posting.google.c om...
> > > > > > No answer?
> > > > > >
> > > > > > If this can't be done then does anyone have a work around?
> > > > > > I thought the dotnet framework could do all. I've followed all the
> > > > > > reference material on webcontrol building and thought this would be
> > > > > > trivial.
> > > > > >
> > > > > > If anyone has the answer I will be more than greatfull.
> > > > > >
> > > > > > REgards Nick
> > > > > >
> > > > > >
> > > > > >
> > > > > > [email]nickduran@hotmail.com[/email] (Bob Brunton) wrote in message> not> > > > > > > Hi,
> > > > > > >
> > > > > > > I seen, this asked a number of times at this group but still have> not> > > > > > > seen any complete/rectified/fixed code.
> > > > > > >
> > > > > > > I have created a Composite WebControl, Added a button to it and
> > > > > > > exposed this child button as a property. But the properties are> below.> > > > > > > persisting at design-time. Are the Attributes correct? See Code> those> > working.> > > > > > >
> > > > > > > Now I want to add other controls to this, when/if I get it
> > So> > > > > > > simply extending the button control is not a valid solution.
> > > > > > >
> > > > > > > I know the response to this will be greatly appreciated by all> [DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),> > > > > > > who have tried but failed, asked but were unanwsered.
> > > > > > >
> > > > > > > Thanks for you replies, If you can get this to work .. great Karma
> > > > > > > will come your way.
> > > > > > >
> > > > > > > Regards Nick
> > > > > > >
> > > > > > > using System;
> > > > > > > using System.Web.UI;
> > > > > > > using System.Web.UI.WebControls;
> > > > > > > using System.ComponentModel;
> > > > > > >
> > > > > > > namespace TestWebControls
> > > > > > > {
> > > > > > >
> > > > > > > [
> > > > > > > ToolboxData("<{0}:WebCustomControl1
> > > > > > > runat=server></{0}:WebCustomControl1>"), PersistChildren(false),
> > > > > > > ParseChildren(true)]
> > > > > > > public class WebCustomControl1 :
> > > > > > > System.Web.UI.WebControls.WebControl, INamingContainer
> > > > > > > {
> > > > > > >
> > > > > > > private System.Web.UI.WebControls.TextBox _TextBoxStreet ;//= new
> > > > > > > System.Web.UI.WebControls.TextBox();
> > > > > > >
> > > > > > >
> > > > >> base.CreateChildControls();> > > > > > > PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
> > > > > > > public TextBox Street
> > > > > > > {
> > > > > > > get{
> > > > > > > return _TextBoxStreet;
> > > > > > > }
> > > > > > > }
> > > > > > > protected override void OnInit(EventArgs e)
> > > > > > > {
> > > > > > > EnsureChildControls();
> > > > > > > base.OnInit (e);
> > > > > > > }
> > > > > > >
> > > > > > > protected override void CreateChildControls()
> > > > > > > {
> > > > > > > if(_TextBoxStreet == null)
> > > > > > > {
> > > > > > > _TextBoxStreet = new System.Web.UI.WebControls.TextBox();
> > > > > > > this.Controls.Add(_TextBoxStreet);
> > > > > > > }> > > > > > > }
> > > > > > >
> > > > > > > protected override void Render(HtmlTextWriter output)
> > > > > > > {
> > > > > > > base.Render(output);
> > > > > > > }
> > > > > > > }
> > > > > > > }
> > >
> > >Bob Brunton Guest
-
Alessandro Zifiglio #9
Re: Composite WebControl -- Child Control Property Persistance at Design-time
Bob, me again ;P
I gave this another go and the only way to get this working is to override
every property in the control you want to expose and manually override each
property you want exposed with NotifyParentProperty(True). For complex
types, to make the Parent property receive notification of changes in the
child property's values, the child property must be marked with
NotifyParentProperty(True). I have a hunch that none of the web controls
have this attribute set to true by default and the only way around is to
manually override each attribute and set it to true.
"Bob Brunton" <nickduran@hotmail.com> wrote in message
news:4f8667c2.0402151307.f573145@posting.google.co m...news:<4f8667c2.0402092022.3b526942@posting.google. com>...> Still no response from microsoft?
>
> I will understand if there is a good reason why other controls can't
> be exposed as public properties in a composite control. But I can't
> work it out.
> I have applied all the attributes.
>
> I have included full source code at the beginning of this thread.
>
> [email]nickduran@hotmail.com[/email] (Bob Brunton) wrote in messagemessage news:<G6TVb.5340$HO2.2373@news.edisontel.com>...> > Thanks for your time and effort Alessandro.
> >
> > I've spent a couple of days on this one, it's driving me nuts. I would
> > truely appreciate one of the MS team responding, just to get some
> > closure.
> >
> > Regards Nick Harrow (alia Bob Brunton)
> >
> >
> > "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote inadding> > > This is all actually working without the need to resort to manuallythe> > > the items to viewstate etc. However you get awkward behavior. Awkward
> > > behavoir being that, in vs.net designer the values wont get added tofirst set> > > page until you set another property in the container. For exampletext> > > the properties for your textbox, that is select some styling, add somefrom> > > to its text property and if you went into html view you wont see these
> > > values as you expect them to be. However if you set another propertyvalues for> > > the container that is not part of the textbox, only then are theif> > > your textbox control reflected in html view and saved in the page. Nowworks> > > you went back to look you will notice this change. For the rest it allin the> > > as expected. If you set any values at runtime in code, the values is
> > > persisted during postback.
> > >
> > > I had ran a small test earlier today and never got to see the textboxState> > > designer and thought this werent working and went about Customizingsaveviewstate --loadviewstate --trackviewstate> > > Restoration and overridingclass> > > uselessly ;P
> > >
> > > Now I see the textbox in the designer by associating a custom designerhtml> > > to the control as you will note in the example code i am pasting.
> > >
> > > If the only problem is your wanting the values immidiately shown inno> > > view that is in xml form, which is the expected behavour, then I havemyself> > > idea why this is not taking place. Actually i have been stuck herewith a> > > sometime back with a few complex types of my own when associating itlight> > > custom editor and i worked around dropping my editor as a whole.
> > >
> > > I really hope someone from MS is reading this post and sheds somevs.net> > > here, besides that I will go on thinking that this is a bug in thebehavior.> > > designer. I'm pasting the complete code i have used to test this<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content), _> > >
> > >
> > >
> > > 'Code for WebCustomControl1.vb
> > >
> > > Imports System.Web.UI
> > > Imports System.Web.UI.WebControls
> > > Imports System.ComponentModel
> > > Namespace CustomControls
> > > <DefaultProperty("textbox2"), _
> > > Designer(GetType(CustomControls.Design.SimpleDesig ner)), _
> > > ToolboxData("<{0}:WebCustomControl1
> > > runat=server></{0}:WebCustomControl1>")> _
> > > Public Class WebCustomControl1
> > > Inherits System.Web.UI.WebControls.WebControl
> > > Implements INamingContainer
> > > Private _textbox2 As TextBox
> > >
> > >
> > >
> > >text> > > PersistenceMode(PersistenceMode.InnerProperty), _
> > > Bindable(True), Category("Appearance"), DefaultValue("")> _
> > > Public Property textbox2() As TextBox
> > > Get
> > > If _textbox2 Is Nothing Then
> > > _textbox2 = New TextBox()
> > > End If
> > > Return _textbox2
> > > End Get
> > > Set(ByVal Value As TextBox)
> > > _textbox2 = Value
> > > End Set
> > > End Property
> > > Friend Sub createControlsHierarchy()
> > > Controls.Clear()
> > > Controls.Add(New LiteralControl("<br /><br /><br /><h3>Thethat> > > box: : </h3>"))
> > > Controls.Add(textbox2)
> > > ChildControlsCreated = True
> > > End Sub
> > > Protected Overrides Sub CreateChildControls()
> > >
> > > createControlsHierarchy()
> > >
> > > End Sub
> > > End Class
> > > End Namespace
> > >
> > > '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
> > >
> > > 'code for SimpleDesigner.vb
> > >
> > > Imports System
> > > Imports System.IO
> > > Imports System.Web
> > > Imports System.Web.UI
> > > Imports System.Web.UI.Design
> > > Imports System.Web.UI.WebControls
> > >
> > > Namespace CustomControls.Design
> > > Public Class SimpleDesigner
> > > Inherits System.Web.UI.Design.ControlDesigner
> > >
> > >
> > > Public Overrides Function GetDesignTimeHtml() As String
> > > ' Component is the instance of the component or controlis> > > ' this designer object is associated with. This propertyLEFT:> > > ' inherited from System.ComponentModel.ComponentDesigner.
> > > Dim designTimeHTML As String
> > > Dim Instance As WebCustomControl1 = CType(Component,
> > > WebCustomControl1)
> > >
> > > If Not Instance.textbox2 Is Nothing Then
> > > Instance.createControlsHierarchy()
> > > designTimeHTML = MyBase.GetDesignTimeHtml
> > > Return designTimeHTML
> > > Else
> > > Return GetEmptyDesignTimeHtml()
> > > End If
> > > End Function
> > > End Class
> > > End Namespace
> > >
> > > '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
> > >
> > > 'code for webform1.aspx
> > >
> > > <body MS_POSITIONING="GridLayout">
> > > <form id="Form1" method="post" runat="server">
> > > <cc1:WebCustomControl1 id="WebCustomControl11" style="Z-INDEX: 101;BackColor="#E0E0E0"> > > 335px; POSITION: absolute; TOP: 224px" runat="server"POSITION:> > > Width="158px">
> > > <textbox2 BackColor="#C0C000" ID="textbox1">
> > > Moi TextBox
> > > </textbox2>
> > > </cc1:WebCustomControl1>
> > > <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 294px;in> > > absolute; TOP: 86px" runat="server" Text="Button"></asp:Button>
> > > </form>
> > > </body>
> > >
> > > '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
> > > 'code for webform1.vb
> > >
> > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs) Handles MyBase.Load
> > > If Not IsPostBack Then
> > > WebCustomControl11.textbox2.Text = "Viewstate Working"
> > > End If
> > > End Sub
> > > "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrotecode> > > message news:4sNVb.5243$HO2.1647@news.edisontel.com...
> > > > Now i see where you are getting at. Simply trying out your sampleloadviewstate and> > does> > > > not persist the data like you stated. I have tried Customizing State
> > > > Restoration with ViewState by overriding saveviewstate,time> > > > trackviewstate but this didnt make a difference. I'll put in someI> > later> > > > this evening and post how far i were able to get ;P
> > > >
> > > >
> > > > "Bob Brunton" <nickduran@hotmail.com> wrote in message
> > > > news:4f8667c2.0402081245.49c99a33@posting.google.c om...
> > > > > Thanks for the reply Alessandro,
> > > > >
> > > > > But I actually want to expose the TextBox as a public property, somore> > > > > do need the attributes for this complex type (TextBox). I wantwrote in> > > > > than just the TextBox Text property.
> > > > >
> > > > > Nick
> > > > >
> > > > >
> > > > >
> > > > > "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com>post ;P> > message news:<vH5Vb.4518$HO2.2345@news.edisontel.com>...> > > > > > Reposting --hope there is no duplicate. I dont see my previousyour> > > > > >
> > > > > > hi Bob, you need to use the textbox controls text property intextbox> > get/set> > > > > > accessors and not supply the control as a whole here. Yourcollection.> > control> > > > > > is persisted already when your adding it to your controlsyour> > The> > > > > > CreatechildControls method is fired after postback which reloadsprerequisite> > > > > > textbox into the controls collection. This is the onlypostback. I've> > for> > > > > > dynamically added controls to persist their state afterDesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)> > also> >> > > > > > noted that you have supplied the
> > > > > >this for> > > > > > attribute to your Get accessor property which is useless, usedont> > PersistenceMode(PersistenceMode.InnerDefaultProper ty)> > > > > > complex types only.> > > > > > also is useless here. all you need to do is :
> > > > > >
> > > > > > public string Street
> > > > > > {
> > > > > > get{
> > > > > > EnsureChildControls();
> > > > > > return _TextBoxStreet.Text;
> > > > > > set
> > > > > > {
> > > > > > EnsureChildControls();
> > > > > > _TextBoxStreet.Text = value;
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > Also note that child controls maintain their own state, and youif> > have to> > childcontrols> > > > > > manually add this to viewstate to have it persist. Make sure you
> > > remove
> > > the
> > > > > > "if conditional statement" you got in CreateChildControls. All> > > > > > you add to the controls collection have to be recreated and yourthe> > > > > > statement breaks this
> > > > > > "Bob Brunton" <nickduran@hotmail.com> wrote in message
> > > > > > news:4f8667c2.0402070342.7768e868@posting.google.c om...
> > > > > > > No answer?
> > > > > > >
> > > > > > > If this can't be done then does anyone have a work around?
> > > > > > > I thought the dotnet framework could do all. I've followed allwould be> > > > > > > reference material on webcontrol building and thought thishave> > news:<4f8667c2.0402051726.2477ec94@posting.google. com>...> > > > > > > trivial.
> > > > > > >
> > > > > > > If anyone has the answer I will be more than greatfull.
> > > > > > >
> > > > > > > REgards Nick
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > [email]nickduran@hotmail.com[/email] (Bob Brunton) wrote in message> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > I seen, this asked a number of times at this group but stilland> > not> > > > > > > > seen any complete/rectified/fixed code.
> > > > > > > >
> > > > > > > > I have created a Composite WebControl, Added a button to itare> > > > > > > > exposed this child button as a property. But the propertiesCode> > not> > > > > > > > persisting at design-time. Are the Attributes correct? Seeall> > below.> > > > > > > >
> > > > > > > > Now I want to add other controls to this, when/if I get it
> > > working.
> > > So
> > > > > > > > simply extending the button control is not a valid solution.
> > > > > > > >
> > > > > > > > I know the response to this will be greatly appreciated byKarma> > those> > > > > > > > who have tried but failed, asked but were unanwsered.
> > > > > > > >
> > > > > > > > Thanks for you replies, If you can get this to work .. greatPersistChildren(false),> > > > > > > > will come your way.
> > > > > > > >
> > > > > > > > Regards Nick
> > > > > > > >
> > > > > > > > using System;
> > > > > > > > using System.Web.UI;
> > > > > > > > using System.Web.UI.WebControls;
> > > > > > > > using System.ComponentModel;
> > > > > > > >
> > > > > > > > namespace TestWebControls
> > > > > > > > {
> > > > > > > >
> > > > > > > > [
> > > > > > > > ToolboxData("<{0}:WebCustomControl1
> > > > > > > > runat=server></{0}:WebCustomControl1>"),;//= new> > > > > > > > ParseChildren(true)]
> > > > > > > > public class WebCustomControl1 :
> > > > > > > > System.Web.UI.WebControls.WebControl, INamingContainer
> > > > > > > > {
> > > > > > > >
> > > > > > > > private System.Web.UI.WebControls.TextBox _TextBoxStreet[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),> >> > > > > > > > System.Web.UI.WebControls.TextBox();
> > > > > > > >
> > > > > > > >
> > > > > >> > base.CreateChildControls();> > > > > > > > PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
> > > > > > > > public TextBox Street
> > > > > > > > {
> > > > > > > > get{
> > > > > > > > return _TextBoxStreet;
> > > > > > > > }
> > > > > > > > }
> > > > > > > > protected override void OnInit(EventArgs e)
> > > > > > > > {
> > > > > > > > EnsureChildControls();
> > > > > > > > base.OnInit (e);
> > > > > > > > }
> > > > > > > >
> > > > > > > > protected override void CreateChildControls()
> > > > > > > > {
> > > > > > > > if(_TextBoxStreet == null)
> > > > > > > > {
> > > > > > > > _TextBoxStreet = new System.Web.UI.WebControls.TextBox();
> > > > > > > > this.Controls.Add(_TextBoxStreet);
> > > > > > > > }> > > > > > > > }
> > > > > > > >
> > > > > > > > protected override void Render(HtmlTextWriter output)
> > > > > > > > {
> > > > > > > > base.Render(output);
> > > > > > > > }
> > > > > > > > }
> > > > > > > > }
> > > >
> > > >
Alessandro Zifiglio Guest
-
Alessandro Zifiglio #10
Re: Composite WebControl -- Child Control Property Persistance at Design-time
and in case its not clear where i'm getting at, your going to have to make a
base class that inherits from say for example textbox control, and then
override every property for textbox you want exposed.
So finally in your control, when exposing a textbox control it will look
like the following :
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
public MyCustomTextBox Street
{
//note above MyCustomTextBox class which inherits
//from textbox and has overridden properties
//with NotifyParentPoperty(True)
get{
return _TextBoxStreet;
}
}
"Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote in
message news:bw1Yb.7743$HO2.5927@news.edisontel.com...each> Bob, me again ;P
>
> I gave this another go and the only way to get this working is to override
> every property in the control you want to expose and manually overridein> property you want exposed with NotifyParentProperty(True). For complex
> types, to make the Parent property receive notification of changes in the
> child property's values, the child property must be marked with
> NotifyParentProperty(True). I have a hunch that none of the web controls
> have this attribute set to true by default and the only way around is to
> manually override each attribute and set it to true.
>
>
> "Bob Brunton" <nickduran@hotmail.com> wrote in message
> news:4f8667c2.0402151307.f573145@posting.google.co m...> news:<4f8667c2.0402092022.3b526942@posting.google. com>...> > Still no response from microsoft?
> >
> > I will understand if there is a good reason why other controls can't
> > be exposed as public properties in a composite control. But I can't
> > work it out.
> > I have applied all the attributes.
> >
> > I have included full source code at the beginning of this thread.
> >
> > [email]nickduran@hotmail.com[/email] (Bob Brunton) wrote in message> > > Thanks for your time and effort Alessandro.
> > >
> > > I've spent a couple of days on this one, it's driving me nuts. I would
> > > truely appreciate one of the MS team responding, just to get some
> > > closure.
> > >
> > > Regards Nick Harrow (alia Bob Brunton)
> > >
> > >
> > > "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wroteAwkward> message news:<G6TVb.5340$HO2.2373@news.edisontel.com>...> adding> > > > This is all actually working without the need to resort to manually> > > > the items to viewstate etc. However you get awkward behavior.some> the> > > > behavoir being that, in vs.net designer the values wont get added to> first set> > > > page until you set another property in the container. For example> > > > the properties for your textbox, that is select some styling, addthese> text> > > > to its text property and if you went into html view you wont seeNow> from> > > > values as you expect them to be. However if you set another property> values for> > > > the container that is not part of the textbox, only then are the> > > > your textbox control reflected in html view and saved in the page.all> if> > > > you went back to look you will notice this change. For the rest ittextbox> works> > > > as expected. If you set any values at runtime in code, the values is
> > > > persisted during postback.
> > > >
> > > > I had ran a small test earlier today and never got to see thedesigner> in the> State> > > > designer and thought this werent working and went about Customizing> saveviewstate --loadviewstate --trackviewstate> > > > Restoration and overriding> > > > uselessly ;P
> > > >
> > > > Now I see the textbox in the designer by associating a customhave> class> html> > > > to the control as you will note in the example code i am pasting.
> > > >
> > > > If the only problem is your wanting the values immidiately shown in> > > > view that is in xml form, which is the expected behavour, then I_> no> myself> > > > idea why this is not taking place. Actually i have been stuck here> with a> > > > sometime back with a few complex types of my own when associating it> light> > > > custom editor and i worked around dropping my editor as a whole.
> > > >
> > > > I really hope someone from MS is reading this post and sheds some> vs.net> > > > here, besides that I will go on thinking that this is a bug in the> behavior.> > > > designer. I'm pasting the complete code i have used to test this> <DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content),> > > >
> > > >
> > > >
> > > > 'Code for WebCustomControl1.vb
> > > >
> > > > Imports System.Web.UI
> > > > Imports System.Web.UI.WebControls
> > > > Imports System.ComponentModel
> > > > Namespace CustomControls
> > > > <DefaultProperty("textbox2"), _
> > > > Designer(GetType(CustomControls.Design.SimpleDesig ner)), _
> > > > ToolboxData("<{0}:WebCustomControl1
> > > > runat=server></{0}:WebCustomControl1>")> _
> > > > Public Class WebCustomControl1
> > > > Inherits System.Web.UI.WebControls.WebControl
> > > > Implements INamingContainer
> > > > Private _textbox2 As TextBox
> > > >
> > > >
> > > >
> > > >/><h3>The> > > > PersistenceMode(PersistenceMode.InnerProperty), _
> > > > Bindable(True), Category("Appearance"), DefaultValue("")> _
> > > > Public Property textbox2() As TextBox
> > > > Get
> > > > If _textbox2 Is Nothing Then
> > > > _textbox2 = New TextBox()
> > > > End If
> > > > Return _textbox2
> > > > End Get
> > > > Set(ByVal Value As TextBox)
> > > > _textbox2 = Value
> > > > End Set
> > > > End Property
> > > > Friend Sub createControlsHierarchy()
> > > > Controls.Clear()
> > > > Controls.Add(New LiteralControl("<br /><br /><brSystem.ComponentModel.ComponentDesigner.> text> that> > > > box: : </h3>"))
> > > > Controls.Add(textbox2)
> > > > ChildControlsCreated = True
> > > > End Sub
> > > > Protected Overrides Sub CreateChildControls()
> > > >
> > > > createControlsHierarchy()
> > > >
> > > > End Sub
> > > > End Class
> > > > End Namespace
> > > >
> > > > '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
> > > >
> > > > 'code for SimpleDesigner.vb
> > > >
> > > > Imports System
> > > > Imports System.IO
> > > > Imports System.Web
> > > > Imports System.Web.UI
> > > > Imports System.Web.UI.Design
> > > > Imports System.Web.UI.WebControls
> > > >
> > > > Namespace CustomControls.Design
> > > > Public Class SimpleDesigner
> > > > Inherits System.Web.UI.Design.ControlDesigner
> > > >
> > > >
> > > > Public Overrides Function GetDesignTimeHtml() As String
> > > > ' Component is the instance of the component or control> is> > > > ' this designer object is associated with. This property> > > > ' inherited from101;> > > > Dim designTimeHTML As String
> > > > Dim Instance As WebCustomControl1 = CType(Component,
> > > > WebCustomControl1)
> > > >
> > > > If Not Instance.textbox2 Is Nothing Then
> > > > Instance.createControlsHierarchy()
> > > > designTimeHTML = MyBase.GetDesignTimeHtml
> > > > Return designTimeHTML
> > > > Else
> > > > Return GetEmptyDesignTimeHtml()
> > > > End If
> > > > End Function
> > > > End Class
> > > > End Namespace
> > > >
> > > > '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
> > > >
> > > > 'code for webform1.aspx
> > > >
> > > > <body MS_POSITIONING="GridLayout">
> > > > <form id="Form1" method="post" runat="server">
> > > > <cc1:WebCustomControl1 id="WebCustomControl11" style="Z-INDEX:State> LEFT:> BackColor="#E0E0E0"> > > > 335px; POSITION: absolute; TOP: 224px" runat="server"> POSITION:> > > > Width="158px">
> > > > <textbox2 BackColor="#C0C000" ID="textbox1">
> > > > Moi TextBox
> > > > </textbox2>
> > > > </cc1:WebCustomControl1>
> > > > <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 294px;> in> > > > absolute; TOP: 86px" runat="server" Text="Button"></asp:Button>
> > > > </form>
> > > > </body>
> > > >
> > > > '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
> > > > 'code for webform1.vb
> > > >
> > > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> > > > System.EventArgs) Handles MyBase.Load
> > > > If Not IsPostBack Then
> > > > WebCustomControl11.textbox2.Text = "Viewstate Working"
> > > > End If
> > > > End Sub
> > > > "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote> code> > > > message news:4sNVb.5243$HO2.1647@news.edisontel.com...
> > > > > Now i see where you are getting at. Simply trying out your sample> > > does
> > > > > not persist the data like you stated. I have tried Customizingso> loadviewstate and> > > > > Restoration with ViewState by overriding saveviewstate,> time> > > > > trackviewstate but this didnt make a difference. I'll put in some> > > later
> > > > > this evening and post how far i were able to get ;P
> > > > >
> > > > >
> > > > > "Bob Brunton" <nickduran@hotmail.com> wrote in message
> > > > > news:4f8667c2.0402081245.49c99a33@posting.google.c om...
> > > > > > Thanks for the reply Alessandro,
> > > > > >
> > > > > > But I actually want to expose the TextBox as a public property,reloads> I> more> > > > > > do need the attributes for this complex type (TextBox). I want> wrote in> > > > > > than just the TextBox Text property.
> > > > > >
> > > > > > Nick
> > > > > >
> > > > > >
> > > > > >
> > > > > > "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com>> post ;P> > > message news:<vH5Vb.4518$HO2.2345@news.edisontel.com>...
> > > > > > > Reposting --hope there is no duplicate. I dont see my previous> your> > > > > > >
> > > > > > > hi Bob, you need to use the textbox controls text property in> textbox> > > get/set
> > > > > > > accessors and not supply the control as a whole here. Your> collection.> > > control
> > > > > > > is persisted already when your adding it to your controls> > > The
> > > > > > > CreatechildControls method is fired after postback whichyou> your> prerequisite> > > > > > > textbox into the controls collection. This is the only> postback. I've> > > for
> > > > > > > dynamically added controls to persist their state after> DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)> > > also
> > > > > > > noted that you have supplied the
> > > > > > >
> > >> this for> > > > > > > attribute to your Get accessor property which is useless, use> > > > > > > complex types only.
> > > PersistenceMode(PersistenceMode.InnerDefaultProper ty)
> > > > > > > also is useless here. all you need to do is :
> > > > > > >
> > > > > > > public string Street
> > > > > > > {
> > > > > > > get{
> > > > > > > EnsureChildControls();
> > > > > > > return _TextBoxStreet.Text;
> > > > > > > set
> > > > > > > {
> > > > > > > EnsureChildControls();
> > > > > > > _TextBoxStreet.Text = value;
> > > > > > > }
> > > > > > > }
> > > > > > >
> > > > > > > Also note that child controls maintain their own state, andyou> dont> > > have to
> > > > > > > manually add this to viewstate to have it persist. Make sureyour> > > > remove
> > > > the
> > > > > > > "if conditional statement" you got in CreateChildControls. All
> > > childcontrols
> > > > > > > you add to the controls collection have to be recreated andall> if> > > > > > > statement breaks this
> > > > > > > "Bob Brunton" <nickduran@hotmail.com> wrote in message
> > > > > > > news:4f8667c2.0402070342.7768e868@posting.google.c om...
> > > > > > > > No answer?
> > > > > > > >
> > > > > > > > If this can't be done then does anyone have a work around?
> > > > > > > > I thought the dotnet framework could do all. I've followedstill> the> would be> > > > > > > > reference material on webcontrol building and thought this> > > > > > > > trivial.
> > > > > > > >
> > > > > > > > If anyone has the answer I will be more than greatfull.
> > > > > > > >
> > > > > > > > REgards Nick
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > [email]nickduran@hotmail.com[/email] (Bob Brunton) wrote in message
> > > news:<4f8667c2.0402051726.2477ec94@posting.google. com>...
> > > > > > > > > Hi,
> > > > > > > > >
> > > > > > > > > I seen, this asked a number of times at this group butit> have> > > not
> > > > > > > > > seen any complete/rectified/fixed code.
> > > > > > > > >
> > > > > > > > > I have created a Composite WebControl, Added a button toproperties> and> > > > > > > > > exposed this child button as a property. But thesolution.> are> Code> > > not
> > > > > > > > > persisting at design-time. Are the Attributes correct? See> > > below.
> > > > > > > > >
> > > > > > > > > Now I want to add other controls to this, when/if I get it
> > > > working.
> > > > So
> > > > > > > > > simply extending the button control is not a validgreat> all> > > > > > > > >
> > > > > > > > > I know the response to this will be greatly appreciated by> > > those
> > > > > > > > > who have tried but failed, asked but were unanwsered.
> > > > > > > > >
> > > > > > > > > Thanks for you replies, If you can get this to work ..> Karma> PersistChildren(false),> > > > > > > > > will come your way.
> > > > > > > > >
> > > > > > > > > Regards Nick
> > > > > > > > >
> > > > > > > > > using System;
> > > > > > > > > using System.Web.UI;
> > > > > > > > > using System.Web.UI.WebControls;
> > > > > > > > > using System.ComponentModel;
> > > > > > > > >
> > > > > > > > > namespace TestWebControls
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > [
> > > > > > > > > ToolboxData("<{0}:WebCustomControl1
> > > > > > > > > runat=server></{0}:WebCustomControl1>"),> ;//= new> > > > > > > > > ParseChildren(true)]
> > > > > > > > > public class WebCustomControl1 :
> > > > > > > > > System.Web.UI.WebControls.WebControl, INamingContainer
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > private System.Web.UI.WebControls.TextBox _TextBoxStreet> [DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),> > > > > > > > > System.Web.UI.WebControls.TextBox();
> > > > > > > > >
> > > > > > > > >
> > > > > > >
> > >>> > > > > > > > > PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
> > > > > > > > > public TextBox Street
> > > > > > > > > {
> > > > > > > > > get{
> > > > > > > > > return _TextBoxStreet;
> > > > > > > > > }
> > > > > > > > > }
> > > > > > > > > protected override void OnInit(EventArgs e)
> > > > > > > > > {
> > > > > > > > > EnsureChildControls();
> > > > > > > > > base.OnInit (e);
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > protected override void CreateChildControls()
> > > > > > > > > {
> > > > > > > > > if(_TextBoxStreet == null)
> > > > > > > > > {
> > > > > > > > > _TextBoxStreet = new System.Web.UI.WebControls.TextBox();
> > > > > > > > > this.Controls.Add(_TextBoxStreet);
> > > > > > > > > }
> > > base.CreateChildControls();
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > protected override void Render(HtmlTextWriter output)
> > > > > > > > > {
> > > > > > > > > base.Render(output);
> > > > > > > > > }
> > > > > > > > > }
> > > > > > > > > }
> > > > >
> > > > >
>
Alessandro Zifiglio Guest



Reply With Quote

