hi , I am trying to add a usercontrol to the control collection of a
webcontrol but I get "Object reference not set to an instance of an object."
errors.On the other hand , by changing the code creating Usercontrol to
create a Webcontrol (label ,textbox etc) I can use it successfully.I think
there is a problem with childcontrolscreating.Is there any ideas ?
Note that : ListSelection is my user control.
-ersin gençtürk
I am sending the source code below :
public class ProductGroups: System.Web.UI.WebControls.WebControl,
INamingContainer
{
private bool _EditMode;
public ProductGroups()
{
}
/// <summary>
/// Turns control into editing mode
/// </summary>
public bool EditMode
{
get
{
return(_EditMode);
}
set
{
_EditMode=value;
}
}
protected override void CreateChildControls()
{
base.CreateChildControls ();
this.EnsureChildControls();
if (EditMode)
{
ListSelection ListSelection1=new ListSelection();
ListSelection1.DataValueField="ProductGroupId";
ListSelection1.DataTextField="ProductGroupName";
ListSelection1.NotSelectedItemsDataSource=//Some datasource code.
ListSelection1.NotSelectedItemsDataBind();
Controls.Add(ListSelection1);
}
else
{
Controls.Add(ProductGroupList1);
}
}
}