dear friends , I created the composit control and put the formview inside that , I got this exception :
Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.Table'.
after set this line
if (!Page.IsPostBack) _template.InstantiateIn(_fv);
would you please help me to find the good solution . here is my code :
[ToolboxData("<{0}:SimpleForm runat=server></{0}:SimpleForm>")]
[ParseChildren(true)]
[Designer("Web.UI.Form, Web.UI", typeof(IDesigner))]
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public class SimpleForm : CompositeControl
{
readonly FormView _fv;
public SimpleForm()
{
_fv = new FormView { DefaultMode = FormViewMode.Edit, Width = Unit.Percentage(100) };
}
private IBindableTemplate _template = null;
[PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(FormView), BindingDirection.TwoWay)]
public IBindableTemplate FormTemplate
{
get { return _template; }
set { _template = value; }
}
protected override void OnLoad(EventArgs e)
{
if (_template != null)
{
_fv.InsertItemTemplate = _fv.EditItemTemplate = _template;
if (!Page.IsPostBack) _template.InstantiateIn(_fv);
}
base.OnLoad(e);
}
protected override void CreateChildControls()
{
Controls.Add(_fv);
}
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Div;
}
}
internal void GetDesignTimeHtml()
{
EnsureChildControls();
}
}