Ejemplo n.º 1
0
    /// -----------------------------------------------------------------------------------------------------------------------------------------------------------------
    /// <summary>
    /// Load the view state from persistent medium.
    /// </summary>
    /// <remarks>
    /// <author>jhill</author>
    /// <creation>Wednesday, 30 May 2007</creation>
    /// </remarks>
    /// -----------------------------------------------------------------------------------------------------------------------------------------------------------------

    public override void Load()
    {
        // Load view state from DB
        string pageViewState = PageViewStateServices.GetByID(GetViewStateID());

        if (pageViewState == null)
        {
            ViewState    = null;
            ControlState = null;
        }
        else
        {
            // Deserialize into a Pair of ViewState and ControlState objects
            IStateFormatter formatter = StateFormatter;
            Pair            statePair = (Pair)formatter.Deserialize(pageViewState);

            // Update ViewState and ControlState
            ViewState    = statePair.First;
            ControlState = statePair.Second;
        }
    }
Ejemplo n.º 2
0
    /// -----------------------------------------------------------------------------------------------------------------------------------------------------------------
    /// <summary>
    /// Save the view state to persistent medium.
    /// </summary>
    /// <remarks>
    /// <author>jhill</author>
    /// <creation>Wednesday, 30 May 2007</creation>
    /// </remarks>
    /// <param name="viewState">View state to save.</param>
    /// -----------------------------------------------------------------------------------------------------------------------------------------------------------------

    public override void Save()
    {
        // Create a pair for ViewState and ControlState
        Pair            statePair = new Pair(ViewState, ControlState);
        IStateFormatter formatter = StateFormatter;

        // Save the view state
        Guid id = GetViewStateID();

        PageViewStateServices.Save(id, formatter.Serialize(statePair));

        // Store the ID of the view state in a hidden form field
        HtmlInputHidden control = _page.FindControl("__VIEWSTATEID") as HtmlInputHidden;

        if (control == null)
        {
            ScriptManager.RegisterHiddenField(_page, "__VIEWSTATEID", id.ToString());
        }
        else
        {
            control.Value = id.ToString();
        }
    }