Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Child tags disappearing

Child tags disappearing

Scheduled Pinned Locked Moved ASP.NET
designcsharpvisual-studiosysadminhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jan larsen
    wrote on last edited by
    #1

    I'm about to develop some WebControls that should ease the webdesign in a project. But I'm having some problems with composite controls.

    1. When I add a child tag for a server control, the control isn't automatically defined in the codebehind page.

    2. If I change a property for the main control using the property browser in VS.NET, all the child tags disappears.

    I can live with the first problem, but the second is somewhat of a timebomb. Here's the code:

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.Design;
    using System.Web.UI.WebControls;
    
    namespace MyControls
    {
    	#region GreyBox
    
    	/// 
    	/// A control for putting the child elements inside the inner cell in a table.
    	/// 
    	[ToolboxData("<{0}:GreyBox runat='server'>")]
    	[ParseChildren(true, "BoxChildren")]
    	[DesignerAttribute(typeof(GreyBoxDesigner), typeof(IDesigner))]
    	public class GreyBox : System.Web.UI.WebControls.WebControl, INamingContainer
    	{
    		#region MEMBER VARIABLES
    
    		/// 
    		/// The collection of child controls.
    		/// 
    		protected readonly ControlCollection boxChildren;
    
    		#endregion
    
    		#region CONSTRUCTORS
    
    		/// 
    		/// Creates a new instance of this control.
    		/// 
    		public GreyBox(): base("table")
    		{
    			this.boxChildren = new ControlCollection(this);
    			this.CssClass = "greybox";
    		}
    
    		#endregion
    
    		#region PROPERTIES
    
    		protected override void AddParsedSubObject(object obj)
    		{
    			if (obj is Control)
    			{
    				boxChildren.Add(obj as Control);
    			}
    		}
    		
    
    		/// 
    		/// The collection of child controls.
    		/// 
    		[Bindable(false), Category("Appearance")] 
    		public ControlCollection BoxChildren
    		{
    			get
    			{
    				return boxChildren;
    			}
    		}		
    
    		#endregion
    
    		#region METHODS
    
    		public static TableRow CreateAndAddTableRow(string cssClass, ControlCollection collection)
    		{
    			TableRow tr = new TableRow();
    			tr.CssClass = cssClass;
    			collection.Add(tr);
    			return tr;
    		}
    
    		public static TableCell CreateAndAddTableCell(string cssClass, WebControl ctrl)
    		{
    			TableCell td = new TableCell();
    			td.CssClass = cssClass;
    			ctrl.Controls.Add(td);
    			return td;
    		}
    
    		public static void CreateChildControlsAndInsertIntoControl(ControlCollection collection, ControlCollection boxChildren)
    		{
    			TableRow		row1		= CreateAndA
    
    M 1 Reply Last reply
    0
    • J jan larsen

      I'm about to develop some WebControls that should ease the webdesign in a project. But I'm having some problems with composite controls.

      1. When I add a child tag for a server control, the control isn't automatically defined in the codebehind page.

      2. If I change a property for the main control using the property browser in VS.NET, all the child tags disappears.

      I can live with the first problem, but the second is somewhat of a timebomb. Here's the code:

      using System;
      using System.Collections;
      using System.ComponentModel;
      using System.ComponentModel.Design;
      using System.Text;
      using System.Web.UI;
      using System.Web.UI.Design;
      using System.Web.UI.WebControls;
      
      namespace MyControls
      {
      	#region GreyBox
      
      	/// 
      	/// A control for putting the child elements inside the inner cell in a table.
      	/// 
      	[ToolboxData("<{0}:GreyBox runat='server'>")]
      	[ParseChildren(true, "BoxChildren")]
      	[DesignerAttribute(typeof(GreyBoxDesigner), typeof(IDesigner))]
      	public class GreyBox : System.Web.UI.WebControls.WebControl, INamingContainer
      	{
      		#region MEMBER VARIABLES
      
      		/// 
      		/// The collection of child controls.
      		/// 
      		protected readonly ControlCollection boxChildren;
      
      		#endregion
      
      		#region CONSTRUCTORS
      
      		/// 
      		/// Creates a new instance of this control.
      		/// 
      		public GreyBox(): base("table")
      		{
      			this.boxChildren = new ControlCollection(this);
      			this.CssClass = "greybox";
      		}
      
      		#endregion
      
      		#region PROPERTIES
      
      		protected override void AddParsedSubObject(object obj)
      		{
      			if (obj is Control)
      			{
      				boxChildren.Add(obj as Control);
      			}
      		}
      		
      
      		/// 
      		/// The collection of child controls.
      		/// 
      		[Bindable(false), Category("Appearance")] 
      		public ControlCollection BoxChildren
      		{
      			get
      			{
      				return boxChildren;
      			}
      		}		
      
      		#endregion
      
      		#region METHODS
      
      		public static TableRow CreateAndAddTableRow(string cssClass, ControlCollection collection)
      		{
      			TableRow tr = new TableRow();
      			tr.CssClass = cssClass;
      			collection.Add(tr);
      			return tr;
      		}
      
      		public static TableCell CreateAndAddTableCell(string cssClass, WebControl ctrl)
      		{
      			TableCell td = new TableCell();
      			td.CssClass = cssClass;
      			ctrl.Controls.Add(td);
      			return td;
      		}
      
      		public static void CreateChildControlsAndInsertIntoControl(ControlCollection collection, ControlCollection boxChildren)
      		{
      			TableRow		row1		= CreateAndA
      
      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      + The ToolboxData attribute should be used as below:

      [ToolboxData("<{0}:GreyBox runat='server'></{0}:GreyBox>")]

      + Any child element should be added between the opening and closing tags of the BoxChildren element. + In order for child controls not to disappear when setting the parent properties at design time, the BoxChildren property should be serialized and persisted with the DesignerSerializationVisibility and PersistenceMode attributes For more information on these attributes, see MSDN DesignerSerializationVisibilityAttribute Class[^] PersistenceModeAttribute Class[^]

      J 1 Reply Last reply
      0
      • M minhpc_bk

        + The ToolboxData attribute should be used as below:

        [ToolboxData("<{0}:GreyBox runat='server'></{0}:GreyBox>")]

        + Any child element should be added between the opening and closing tags of the BoxChildren element. + In order for child controls not to disappear when setting the parent properties at design time, the BoxChildren property should be serialized and persisted with the DesignerSerializationVisibility and PersistenceMode attributes For more information on these attributes, see MSDN DesignerSerializationVisibilityAttribute Class[^] PersistenceModeAttribute Class[^]

        J Offline
        J Offline
        jan larsen
        wrote on last edited by
        #3

        Thanks! :beer: :rose: And GetPersistInnerHtml() in my builder made it work like a charm. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

        M 1 Reply Last reply
        0
        • J jan larsen

          Thanks! :beer: :rose: And GetPersistInnerHtml() in my builder made it work like a charm. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Oh, thanks for a beer, I might be drunk at the weekend. :-O

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups