LoadViewState not firing on PostBack

Discussion in 'ASP .Net Web Controls' started by Bill Biddy, Jan 20, 2004.

  1. Bill Biddy

    Bill Biddy Guest

    I have search the newsgroups thoroughly and though I have seen several
    posts about similar issues I have never seen one that clearly addresses
    my problem.

    My Control never Gets a LoadViewState Call!

    I have a WebControl that is being created as an item template in a
    databound templated control (DataList). Within my custom control I have
    a complex state Type that wish to add to ViewState. The class that I am
    adding to ViewState implements the IStateManager Interface and is
    defined as:

    //SessionBag contains a SortedList property named List

    public class ViewStateBag : SessionBag, IStateManager
    {
    protected bool _IsTrackingViewState;
    protected StateBag _viewstate;

    public ViewStateBag()
    {
    _viewstate = new StateBag();
    }

    bool IStateManager.IsTrackingViewState
    {
    get
    {
    return this._IsTrackingViewState;
    }
    }

    void IStateManager.LoadViewState(object savedState)
    {
    ArrayList a = new ArrayList();
    ArrayList keys = (ArrayList)_viewstate["Keys"];
    ArrayList values = (ArrayList)_viewstate["Values"];

    for (Int32 x = 0; x < keys.Count; x++)
    {
    List.Add(keys[x], values[x]);
    }
    if (savedState != null)
    ((IStateManager)_viewstate).LoadViewState(savedState);
    }

    object IStateManager.SaveViewState()
    {
    if( (!((IDictionary)_viewstate).Contain("SkillsStateBag")) ||
    (_viewstate.IsItemDirty("SkillsStateBag")))
    {
    _viewstate.Clear();
    ArrayList keys = new ArrayList();
    ArrayList values = new ArrayList();

    foreach (DictionaryEntry d in List)
    {
    keys.Add(d.Key);
    values.Add(d.Value);
    }

    _viewstate["Keys"] = keys;
    _viewstate["Values"] = values;
    }
    _viewstate.SetItemDirty("Keys", true);
    _viewstate.SetItemDirty("Values", true);
    return ((IStateManager)_viewstate).SaveViewState();
    }

    void IStateManager.TrackViewState()
    {
    this._IsTrackingViewState = true;
    ((IStateManager)_viewstate).TrackViewState();
    }
    }


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Bill Biddy, Jan 20, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William F. Robertson, Jr.

    LoadViewState not firing

    William F. Robertson, Jr., Apr 16, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    4,385
    William F. Robertson, Jr.
    Apr 16, 2004
  2. =?Utf-8?B?RGV2aW4gRmVuc3RlcmhlaW0=?=

    LoadViewState not firing when Control added with AddAt

    =?Utf-8?B?RGV2aW4gRmVuc3RlcmhlaW0=?=, Jul 18, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    3,486
    Jyoti Ballabh
    Nov 26, 2009
  3. J.
    Replies:
    0
    Views:
    1,862
  4. Umbaga

    LoadViewState override not firing in UserControl

    Umbaga, Dec 9, 2003, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    258
    Umbaga
    Dec 10, 2003
  5. jsc

    Derived TreeNode LoadViewState not firing

    jsc, Jan 12, 2009, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    198
Loading...

Share This Page