Mantain ViewState

J

Jonathan

Hello,
I'm writed a WebCustomControl but I can't mantain the viewstate. This is the
code of my WebCustomContol:

public class WebCustomControl1 : System.Web.UI.WebControls.WebControl,
IPostBackEventHandler
{
public event EventHandler DoPostBack;
protected override void Render(HtmlTextWriter output)
{
output.Write(GetControlHTML());
}
private string GetControlHTML()
{
StringWriter TextBoxWriter = new StringWriter();
HtmlTextWriter ControlWriter = new HtmlTextWriter(TextBoxWriter);
TextBox box = new TextBox();
box.ID = "txtViewState";
if(ViewState["txtViewState"] == null)
ViewState.Add("txtViewState","Testeando");
box.Text = (string)ViewState["txtViewState"];
box.RenderControl(ControlWriter);
Button button = new Button();
button.Text = "DoPostBack";

button.Attributes.Add("onclick",Page.GetPostBackClientEvent(button,"doPostBa
ck"));
button.RenderControl(ControlWriter);
return TextBoxWriter.ToString();
}
public void RaisePostBackEvent(string eventArgument)
{
if(eventArgument == "doPostBack")
{
if(this.DoPostBack != null)
this.DoPostBack(this,EventArgs.Empty);
}
}
}

* The Page.EnableViewState is true

Somebody knows how is the correct way to mantain the ViewState?

Thanks!
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top