composite controlhttp://forums.asp.net/t/1619590.aspx/1?composite+controlSun, 14 Nov 2010 04:48:38 -050016195904152764http://forums.asp.net/p/1619590/4152764.aspx/1?composite+controlcomposite control <p>Hi to all,<br> <br> I am creating a composite control. On the selection of item in the dropdownlist, the result should be shown. But its mismatching the result. Here is the code for the control:</p> <p><pre class="prettyprint">public class FormExtenderControl : CompositeControl { //private static readonly object EventSubmitKey = new object(); private workspaceEntities entity = new workspaceEntities(); [Bindable(true)] [Category(&quot;Appearance&quot;)] [DefaultValue(&quot;&quot;)] [Localizable(true)] public string Text { get { String s = (String)ViewState[&quot;Text&quot;]; return ((s == null) ? &quot;[&quot; &#43; this.ID &#43; &quot;]&quot; : s); } set { ViewState[&quot;Text&quot;] = value; } } public virtual string entityid { get { string s = (string)ViewState[&quot;entityid&quot;]; return (s == null) ? string.Empty : s; } set { ViewState[&quot;entityid&quot;] = value; } } protected override void CreateChildControls() { this.Controls.Clear(); int entityID = int.Parse(entityid); var additionalfield = (from p in entity.EntitiesAdditionalFields join pn in entity.Fields on p.FieldId equals pn.Id join pnn in entity.FieldTypes on pn.TypeId equals pnn.Id where p.EntitiyId == entityID select p).ToList(); Table tbl = new Table(); TableRow temp = new TableRow(); tbl.Rows.Add(temp); TableCell tempcell = new TableCell(); temp.Cells.Add(tempcell); Label entityIdLabel = new Label(); entityIdLabel.Text = entityid; tempcell.Controls.Add(entityIdLabel); foreach (var item in additionalfield) { TableRow row = new TableRow(); tbl.Rows.Add(row); string fieldtype = item.Field.FieldType.Name; TableCell cell = new TableCell(); Label lbl = new Label(); lbl.Text = item.Field.Label; cell.Controls.Add(lbl); row.Cells.Add(cell); switch (fieldtype) { case &quot;SingleLineText&quot;: TextBox txt = new TextBox(); txt.Text = item.DefaultValue; if (item.Field.MaxLength != null) { txt.MaxLength = int.Parse(item.Field.MaxLength.ToString()); } cell = new TableCell(); cell.Controls.Add(txt); row.Cells.Add(cell); break; case &quot;MultiLineText&quot;: TextBox multitxt = new TextBox(); multitxt.TextMode = TextBoxMode.MultiLine; multitxt.Text = item.DefaultValue; if (item.Field.MaxLength != null) { multitxt.MaxLength = int.Parse(item.Field.MaxLength.ToString()); } cell = new TableCell(); cell.Controls.Add(multitxt); row.Cells.Add(cell); break; } } this.Controls.Add(tbl); base.CreateChildControls(); } protected override void RecreateChildControls() { EnsureChildControls(); } }</pre><br> </p> <p>If I have a breakpoint on the selection index changed event of the dropdownlist, then on every selection it should go to the event. Problem is when I select an item which makes the &quot;singlelineText&quot; textbox to appear and after it I select any other item, it doesn't stop at the dropdown event instead it goes to the &quot;CreateChildControls&quot; method of the composite control which results in wrong data.<br> <br> <br> Please assist me...</p> <p><br> </p> <p>Cheers</p> <p>Sneha<br> </p> 2010-11-03T09:48:01-04:004155653http://forums.asp.net/p/1619590/4155653.aspx/1?Re+composite+controlRe: composite control <p>Hi,</p> <p>I cannot run and reproduce the issue on my side. </p> <p>Can you help take out some not necessary code and provide us the least runnable code to produce the issue on our side? So we can clearly see the issue and dip into the troubleshooting.</p> <p>Thanks.</p> 2010-11-05T06:48:35-04:004167821http://forums.asp.net/p/1619590/4167821.aspx/1?Re+composite+controlRe: composite control <p>I didn't see a dropdownlist. I saw some tables and textboxes.</p> <p>Your control format is wrong, so your not getting the desired results, or correct operation when running it. so fix the format first, and your control will work right.</p> <p>When you create something in createchildcontrol, it's a one time shot in creating html output. But it doesn't work right in forms. CreateChildControls is pretty raw, and you have to add viewstate information. Use OnInit instead. Read the post below to get a better idea, and so I don't have to type more.<br> </p> <p>http://forums.asp.net/t/1609134.aspx</p> <p>With all due respect, whats up with the baby pictures. I know your proud of your kid, but is it a mask to hide behind, sub consciously? Im just curious.&nbsp; don't mean to be offensive and I'm not attacking .<br> </p> <p><br> </p> 2010-11-14T04:48:38-05:00