BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Server Control and Component Development by Dr. Shahram Khosravi; ISBN: 9780471793502
You are currently viewing the BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
I am Developing a custom grid.i am managing my viewstate manually through implementing the IStateManager.
The problem is that NON OF SaveViewState And LoadViewState Events EVER get fired and i can't figure out why?!
i have seen lots of articles on it,Please Do not direct me to a link.i haven't found any answers by myself.Thanks In advance.
I have tried the simplest form possible to see what's wrong but i have the same problem in this little code again ,here is the 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()
{
object[] State = new object[2];
State[0] = base.SaveViewState ();
State[1] = "hi";
return State;
}
void IStateManager.LoadViewState(object state)
{
base.LoadViewState(state);
if (state == null)
return;
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