M
Mark Sisson
Easy one for gurus::::
Could someone tell me why this custom control bombs during postback?
To duplicate: compile this control, put it in your toolbox, drag it to
a new form, add a button to the form, run the form, hit the button.
Voila! The control doesn't remember it's ViewState.
WHY!!!!!!!!!!!!!!!!!!!!!!!!!!!!
tia
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace ViewStateTestControl
{
[DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>")]
public class WebCustomControl1 :
System.Web.UI.WebControls.WebControl, INamingContainer
{
public WebCustomControl1()
{
this.EnableViewState = true;
}
protected override void Render(HtmlTextWriter output)
{
if (!Page.IsPostBack) ViewState["a"] = "a";
output.Write(ViewState["a"].ToString());
}
}
}
Could someone tell me why this custom control bombs during postback?
To duplicate: compile this control, put it in your toolbox, drag it to
a new form, add a button to the form, run the form, hit the button.
Voila! The control doesn't remember it's ViewState.
WHY!!!!!!!!!!!!!!!!!!!!!!!!!!!!
tia
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace ViewStateTestControl
{
[DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>")]
public class WebCustomControl1 :
System.Web.UI.WebControls.WebControl, INamingContainer
{
public WebCustomControl1()
{
this.EnableViewState = true;
}
protected override void Render(HtmlTextWriter output)
{
if (!Page.IsPostBack) ViewState["a"] = "a";
output.Write(ViewState["a"].ToString());
}
}
}