Try use the code below that I have been modified from your code
namespace GridControl
{
public class MabnaGrid : GridView, IStateManager
{
public MabnaGrid()
{
}
bool IStateManager.IsTrackingViewState
{
get { return base.IsTrackingViewState; }
}
void IStateManager.TrackViewState()
{
base.TrackViewState();
}
object IStateManager.SaveViewState()
{
return this.SaveViewState();
}
void IStateManager.LoadViewState(object state)
{
this.LoadViewState(state);
}
protected override object SaveViewState()
{
object[] State = new object[2];
State[0] = base.SaveViewState();
State[1] = "hi";
return State;
}
protected override void LoadViewState(object savedState)
{
string test = String.Empty;
if (savedState != null)
{
object[] state = savedState as object[];
if (state != null && state.Length == 2)
{
base.LoadViewState(state[0]);
if (state[1] != null)
test = (string)state[1]; //state[1] contain "hi"
}
}
else
base.LoadViewState(savedState);
}
}
}
My assumption is that You want to create custom GridView that inherits from GridView class.
So my answer is based on my assumption
Your SaveViewState and LoadViewState never run, because you don't override SaveViewState() and LoadViewState() methods that the GridView class have already implemented from Control base class.
The IStateManager should be used if MabnaGrid contains complex property that MabnaGrid want to save to ViewState.
So the Complex Property itself should implement IStateManager(not the MabnaGrid class), then MabnaGrid class can call SaveViewState() method from ComplexProperty to save the Complex property value to the ViewState. To call SaveViewState() method from ComplexProperty, MabnaGrid must convert the complex property to IStateManager, because of the access modifier.
Please give the correction if I misunderstanding the concept and Your question
|