<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Custom Server Controls</title><link>http://forums.asp.net/19.aspx</link><description>All about building ASP.NET server controls. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=12&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: CompositeControl not saving child controls viewstate</title><link>http://forums.asp.net/thread/3259791.aspx</link><pubDate>Fri, 26 Jun 2009 10:23:20 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3259791</guid><dc:creator>Slipperman</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3259791.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=19&amp;PostID=3259791</wfw:commentRss><description>&lt;p&gt;1. have you checked the value of _menuOptionList in debug to make sure it&amp;#39;s not null?&lt;/p&gt;&lt;p&gt;2. if it is, try placing the value of _menuOptionList in the ViewState collection within the property then refer to it via the property name (MenuOptions) in CreateChildControls. also try commenting out EnsureChildControls for now.&lt;/p&gt;&lt;p&gt;3. you&amp;#39;re switching on &lt;span&gt;&lt;span&gt;menuOption.SelectionType for 2 possible values. but where is this actually set to one or the other? there&amp;#39;s no reference to it.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Re: CompositeControl not saving child controls viewstate</title><link>http://forums.asp.net/thread/3259268.aspx</link><pubDate>Fri, 26 Jun 2009 05:44:48 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3259268</guid><dc:creator>bhav27</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3259268.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=19&amp;PostID=3259268</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;Slipperman:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;
&lt;p&gt;you might want to repost your problem description (hard to read). no need to put it in a code segment - just use the regular textbox.&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When I tried to insert problem text at the top of code the richtextbox here takes my text as code so I had to put it at the end.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;</description></item><item><title>Re: CompositeControl not saving child controls viewstate</title><link>http://forums.asp.net/thread/3257526.aspx</link><pubDate>Thu, 25 Jun 2009 11:03:15 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3257526</guid><dc:creator>Slipperman</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3257526.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=19&amp;PostID=3257526</wfw:commentRss><description>&lt;p&gt;you might want to repost your problem description (hard to read). no need to put it in a code segment - just use the regular textbox.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>CompositeControl not saving child controls viewstate</title><link>http://forums.asp.net/thread/3256880.aspx</link><pubDate>Thu, 25 Jun 2009 06:01:24 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3256880</guid><dc:creator>bhav27</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3256880.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=19&amp;PostID=3256880</wfw:commentRss><description>&lt;pre class="c-sharp" name="code"&gt;&lt;p&gt;using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using eBizTakeAway.WebStore.Catalogue;
using eBizSuite.Common.Shared;

namespace eBizTakeAway.Web.UI.ServerControls
{
	[ToolboxData(&amp;quot;&amp;lt;{0}:MenuOptionsConfig runat=server&amp;gt;&amp;lt;/{0}:MenuOptionsConfig&amp;gt;&amp;quot;)]
	public class MenuOptionsConfig : CompositeControl
	{
		#region private members

		protected MenuOptionCollection _menuOptionList;
		protected CatalogMenuOptionCollection _catalogMenuOptionList;

		#endregion

		#region private methods

		protected void CreateSingleSelectionControl(MenuOptions menuOption, bool bDataBind)
		{
			CheckBoxList chkList = new CheckBoxList();
			Controls.Add(chkList);

			if (bDataBind)
			{
				chkList.ID = menuOption.OptionName.Replace(&amp;quot; &amp;quot;, &amp;quot;&amp;quot;);
				chkList.RepeatDirection = RepeatDirection.Horizontal;
				chkList.RepeatColumns = 3;

				chkList.DataSource = menuOption.Options;
				chkList.DataTextField = &amp;quot;Name&amp;quot;;
				chkList.DataValueField = &amp;quot;Name&amp;quot;;
				chkList.DataBind();
			}
		}

		protected void CreateMultiSelectionControl(MenuOptions menuOption, bool bDataBind)
		{
			RadioButtonList rblList = new RadioButtonList();
			Controls.Add(rblList);

			if (bDataBind)
			{
				rblList.ID = menuOption.OptionName.Replace(&amp;quot; &amp;quot;, &amp;quot;&amp;quot;);
				rblList.RepeatDirection = RepeatDirection.Horizontal;
				rblList.RepeatColumns = 3;

				rblList.DataSource = menuOption.Options;
				rblList.DataTextField = &amp;quot;Name&amp;quot;;
				rblList.DataValueField = &amp;quot;Name&amp;quot;;
				rblList.DataBind();
			}
		}

		#endregion

		#region public properties

		public MenuOptionCollection MenuOptions
		{
			set
			{
				_menuOptionList = value;

				EnsureChildControls();
			}
		}

		public CatalogMenuOptionCollection CatalogMenuOptions
		{
			get
			{
				return _catalogMenuOptionList;
			}
		}

		#endregion

		#region overridable members

		protected override void CreateChildControls()
		{
			try
			{
				if (_menuOptionList != null)
				{
					_menuOptionList.GetCollection().ForEach(menuOption =&amp;gt;
						{
							LiteralControl header = new LiteralControl(string.Format(&amp;quot;&amp;lt;h2&amp;gt;{0}&amp;lt;/h2&amp;gt;&amp;quot;, menuOption.OptionName));

							LiteralControl desc = new LiteralControl();
							if (menuOption.Description != string.Empty)
								desc = new LiteralControl(string.Format(&amp;quot;&amp;lt;h3&amp;gt;{0}&amp;lt;/h3&amp;gt;&amp;quot;, menuOption.Description));

							Controls.Add(header);
							Controls.Add(desc);

							switch (menuOption.SelectionType)
							{
								case MenuOptionSelectionType.Single:
									CreateSingleSelectionControl(menuOption, !Page.IsPostBack);
									break;
								case MenuOptionSelectionType.Multiple:
									CreateMultiSelectionControl(menuOption, !Page.IsPostBack);
									break;
							}
						});
				}
			}
			catch (Exception ex)
			{
				throw ex;
			}
			finally
			{
				base.CreateChildControls();
			}
		}

		#endregion

		#region public methods

		#endregion

		#region event handlers

		#endregion
	}
}
&lt;/p&gt;&lt;/pre&gt;
&lt;p&gt;Above is the code I am currently using to develop my custom server control. Basically based on &amp;quot;MenuOptions&amp;quot; property which user sets the control builds by Child controls. The big problem here I have is when user postbacks the control fails to render the child controls. I tried to debug and found out that in the first postback the debugger directly goes to CreateChildControls() rather page_load() of the page.&lt;/p&gt;
&lt;p&gt;On the second postback the debugger behaves normally but never renders checkboxlist and radiobuttonlist in the child controls but just literalcontrols.&lt;/p&gt;
&lt;p&gt;Can someone review the code and let me know what I am doing wrong or missing here?&lt;/p&gt;</description></item></channel></rss>