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:
public class FormExtenderControl : CompositeControl
{
//private static readonly object EventSubmitKey = new object();
private workspaceEntities entity = new workspaceEntities();
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? "[" + this.ID + "]" : s);
}
set
{
ViewState["Text"] = value;
}
}
public virtual string entityid
{
get
{
string s = (string)ViewState["entityid"];
return (s == null) ? string.Empty : s;
}
set
{
ViewState["entityid"] = 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 "SingleLineText":
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 "MultiLineText":
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();
}
}
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 "singlelineText" textbox to appear and after it I select any other item,
it doesn't stop at the dropdown event instead it goes to the "CreateChildControls" method of the composite control which results in wrong data.
Please assist me...
Cheers
Sneha
Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
snehachoudha...
Member
284 Points
165 Posts
composite control
Nov 03, 2010 09:48 AM|LINK
Hi to all,
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:
public class FormExtenderControl : CompositeControl { //private static readonly object EventSubmitKey = new object(); private workspaceEntities entity = new workspaceEntities(); [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] public string Text { get { String s = (String)ViewState["Text"]; return ((s == null) ? "[" + this.ID + "]" : s); } set { ViewState["Text"] = value; } } public virtual string entityid { get { string s = (string)ViewState["entityid"]; return (s == null) ? string.Empty : s; } set { ViewState["entityid"] = 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 "SingleLineText": 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 "MultiLineText": 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(); } }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 "singlelineText" textbox to appear and after it I select any other item, it doesn't stop at the dropdown event instead it goes to the "CreateChildControls" method of the composite control which results in wrong data.
Please assist me...
Cheers
Sneha