Viewstate errors... how do I get viewstate working?

Discussion in 'ASP .Net Building Controls' started by mark, Feb 20, 2004.

  1. mark

    mark Guest

    Hi all,

    Have to say I can't for the life of me get this viewstate business
    working with collections of classes!

    The current error I'm getting is

    'MSS.ProgressBar' does not implement interface member
    'System.Web.UI.IStateManager.LoadViewState(object)'.
    'MSS.ProgressBar.LoadViewState(object)' is either static, not public,
    or has the wrong return type.

    This is for LoadViewState, SaveViewState & TrackViewState.

    The following code comes from a userontrol I'm using as a progress
    bar. I've cut some irrelevant code out. I would really appreciate it
    if someone could tell me what I'm doing wrong.

    I define my class as
    >>public class ProgressBar : System.Web.UI.UserControl,

    System.Web.UI.IStateManager

    I create a new instance of my collection
    >>private Items _itms = new Items();


    Further on I expose the collection as a property.

    At the end I override the IsTrackViewState property and LoadViewState,
    SaveViewState & TrackViewState functions.

    Where Am I going wrong?

    Thanks in advance,

    Mærk...


    namespace MSS
    {
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    public enum Positioning
    {
    Horizontal = 0,
    Vertical = 1
    }

    /// <summary>
    /// Summary description for ProgressBar.
    /// </summary>
    [Serializable]
    public class ProgressBar : System.Web.UI.UserControl,
    System.Web.UI.IStateManager
    {
    protected System.Web.UI.WebControls.Table myTable;
    protected System.Web.UI.WebControls.TableCell myCell;

    private Items _itms = new Items();

    private void Page_Load(object sender, System.EventArgs e)
    {
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    public Items Items
    {
    get
    {
    if (_itms == null)
    {
    _itms = new Items();
    if (IsTrackingViewState)
    ((IStateManager)_itms).TrackViewState();
    }
    return _itms;
    }
    }


    /// <summary>
    /// Image URL of completed steps
    /// </summary>
    public string CompletedImageURL
    {
    get
    {
    return (string)ViewState["CompletedImageURL"];
    }
    set
    {
    ViewState["CompletedImageURL"] = value;
    }
    }


    public Unit CellWidth
    {
    get
    {
    return (Unit)ViewState["CellWidth"];
    }
    set
    {
    ViewState["CellWidth"] = value;
    }
    }

    public string[] Text
    {
    get
    {
    return (string[])ViewState["Text"];
    }
    set
    {
    ViewState["Text"] = value;
    }
    }

    public int CurrentStep
    {
    get
    {
    return (int)ViewState["CurrentStep"];
    }
    set
    {
    ViewState["CurrentStep"] = value;
    }
    }

    public Color Background
    {
    get
    {
    return (Color)ViewState["Background"];
    }
    set
    {
    ViewState["Background"] = value;
    }
    }

    protected override void CreateChildControls()
    {
    // Here I create my controls. Not relevant to this discussion...
    }

    #region IStateManager Members

    public new bool IsTrackingViewState
    {
    get
    {
    // TODO: Add ProgressBar.IsTrackingViewState getter
    implementation
    return ((IStateManager)_itms).IsTrackingViewState; //true;
    }
    }

    override protected void TrackViewState()
    {
    base.TrackViewState();

    if (_itms != null)
    ((IStateManager)_itms).TrackViewState();
    }

    override protected object SaveViewState()
    {
    return new Pair(base.SaveViewState(),((IStateManager)_itms).SaveViewState());
    }

    override protected void LoadViewState(object state)
    {
    Pair p=(Pair)state;
    if(p==null)return;
    base.LoadViewState(p.First);
    ((IStateManager)_itms).LoadViewState(p.Second);
    }
    #endregion
    }
    }
    mark, Feb 20, 2004
    #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. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    913
    Mark Goldin
    Jan 17, 2004
  2. SenthilVel
    Replies:
    0
    Views:
    924
    SenthilVel
    Jun 7, 2006
  3. George1776

    Out-of-memory errors and caching errors.

    George1776, Aug 28, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,258
    George1776
    Sep 14, 2006
  4. sck10
    Replies:
    6
    Views:
    883
    sck10
    Sep 1, 2006
  5. Lance Wynn
    Replies:
    1
    Views:
    1,805
    Lance Wynn
    Feb 3, 2008
Loading...

Share This Page