Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 25th, 2007, 11:12 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
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;

}
Reply With Quote
  #2 (permalink)  
Old December 3rd, 2008, 03:15 AM
Authorized User
 
Join Date: Oct 2006
Location: Jakarta, , Indonesia.
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

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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



All times are GMT -4. The time now is 02:37 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.