T
timor.super
Hi group,
i'm trying to create a template control, very easy with nothing else a
button in it :
<Test:TestTemplate ID="test" runat="server" />
public class TestTemplate : WebControl, INamingContainer
{
private ITemplate _template;
private TestPanel _panel;
public TestPanel Panel
{
get { EnsureChildControls(); return _panel; }
}
public virtual ITemplate Template
{
get { return _template; }
set { _template = value; }
}
public override ControlCollection Controls
{
get { EnsureChildControls(); return base.Controls; }
}
protected override void CreateChildControls()
{
Controls.Clear();
_panel = new TestPanel();
ITemplate template = Template;
if (template == null)
{
template = new DefaultTemplate();
}
Button b = new Button();
b.Text = "OK";
template.InstantiateIn(_panel);
Controls.Add(_panel);
Controls.Add(b);
}
public override void DataBind()
{
CreateChildControls();
ChildControlsCreated = true;
base.DataBind();
}
private sealed class DefaultTemplate : ITemplate
{
void ITemplate.InstantiateIn(Control container)
{
}
}
}
public class TestPanel : Panel, INamingContainer
{
}
When I click on the button, after postback, I have a
NullReferenceException
the call stack :
[NullReferenceException:]
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +93
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+72
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+3839
What should I do ?
Thanks for your help.
Best regards
i'm trying to create a template control, very easy with nothing else a
button in it :
<Test:TestTemplate ID="test" runat="server" />
public class TestTemplate : WebControl, INamingContainer
{
private ITemplate _template;
private TestPanel _panel;
public TestPanel Panel
{
get { EnsureChildControls(); return _panel; }
}
public virtual ITemplate Template
{
get { return _template; }
set { _template = value; }
}
public override ControlCollection Controls
{
get { EnsureChildControls(); return base.Controls; }
}
protected override void CreateChildControls()
{
Controls.Clear();
_panel = new TestPanel();
ITemplate template = Template;
if (template == null)
{
template = new DefaultTemplate();
}
Button b = new Button();
b.Text = "OK";
template.InstantiateIn(_panel);
Controls.Add(_panel);
Controls.Add(b);
}
public override void DataBind()
{
CreateChildControls();
ChildControlsCreated = true;
base.DataBind();
}
private sealed class DefaultTemplate : ITemplate
{
void ITemplate.InstantiateIn(Control container)
{
}
}
}
public class TestPanel : Panel, INamingContainer
{
}
When I click on the button, after postback, I have a
NullReferenceException
the call stack :
[NullReferenceException:]
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +93
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+72
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+3839
What should I do ?
Thanks for your help.
Best regards