Missing Viewstate in Custom Control

Discussion in 'ASP .Net' started by Mark Sisson, Jul 19, 2003.

  1. Mark Sisson

    Mark Sisson Guest

    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());
    }
    }
    }
    Mark Sisson, Jul 19, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave A
    Replies:
    0
    Views:
    536
    Dave A
    Nov 27, 2007
  2. Matt Sokol
    Replies:
    2
    Views:
    365
    Theo Tillotson
    Aug 7, 2003
  3. Josema
    Replies:
    2
    Views:
    337
  4. whoisnidhee

    ViewState of the Composite Control composed of custom control

    whoisnidhee, Jul 14, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    312
    Nidhee
    Jul 16, 2004
  5. Josema
    Replies:
    0
    Views:
    197
    Josema
    May 9, 2005
Loading...

Share This Page