Wrox Programmer Forums
|
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
Welcome to the p2p.wrox.com Forums.

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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 25th, 2007, 10:12 AM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default IstateManager Problem

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;

}
 
Old December 3rd, 2008, 03:15 AM
Authorized User
 
Join Date: Oct 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Nicholsen
Default

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
IStateManager.TrackViewState() Ch 17 EdKroket BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 0 January 25th, 2007 07:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.