Link to home
Start Free TrialLog in
Avatar of KaranGupta
KaranGupta

asked on

base.LoadViewState

Hi

What is the purpose of this and is there any scenario where I can use it
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Control.LoadViewState Method

Restores view-state information from a previous page request that was saved by the SaveViewState method.

http://msdn.microsoft.com/en-us/library/system.web.ui.control.loadviewstate(v=vs.85).aspx
Avatar of KaranGupta
KaranGupta

ASKER

Is base.LoadViewState and Control.LoadViewState same
The base keyword is used to access members of the base class from within a derived class:

Call a method on the base class that has been overridden by another method.
Specify which base-class constructor should be called when creating instances of the derived class.
A base class access is permitted only in a constructor, an instance method, or an instance property accessor.

It is an error to use the base keyword from within a static method.

Source: http://msdn.microsoft.com/en-us/library/hfw7t1ce(v=vs.71).aspx
Hi

I have created 2 pages one is source_view_state.aspx and destination_view_state.aspx on the source_view_state. aspx file there is a textbox and a button. On Click of button I have written the following code
ViewState["K"] = TextBox1.Text;
base.SaveViewState();
Response.Redirect("Destination_View_State.aspx");

Open in new window


Now on the destination_view_state.aspx I have written the following code
    protected override void LoadViewState(object savedState)
    {
        object[] states = (object[])savedState;
    }

Open in new window


which I guess is the method in page life cycle for loading viewstate.  This event is not fired. Do we need to call that event explicitly

Textbox1 value is already in viewstate and why you want to create another viewstate ViewState["K"] ?

Use server.transfer to go to next page and user Form["<ID>"] to get the values from the soruce page.
Hi apeter

I was just trying to find out the practical usage of LoadViewState. Could you please help me out?


Regards
Karan Gupta
ASKER CERTIFIED SOLUTION
Avatar of Aaron Jabamani
Aaron Jabamani
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial