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

M

mark

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 asSystem.Web.UI.IStateManager

I create a new instance of my collection
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
}
}
 

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,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top