Missing Viewstate in Custom Control

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());
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top