Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

base.LoadViewState

Hi

What is the purpose of this and is there any scenario where I can use it
0
KaranGupta
Asked:
KaranGupta
  • 3
  • 2
  • 2
1 Solution
 
DhaestCommented:
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
0
 
KaranGuptaAuthor Commented:
Is base.LoadViewState and Control.LoadViewState same
0
 
DhaestCommented:
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
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
KaranGuptaAuthor Commented:
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

0
 
apeterCommented:
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.
0
 
KaranGuptaAuthor Commented:
Hi apeter

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


Regards
Karan Gupta
0
 
apeterCommented:
Hope this gives some idea.

One of the most confusing aspects of creating controls dynamically is that you have to recreate them after postback -- the entire page is recreated on each postback, and although ASP.NET can recreate the controls from the declarative syntax on the page, it doesn't know about any controls that you've added programmatically.
 
 
To add to the confusion, the controls you have added often have some viewstate (ie, they have non-default property settings). Toward the end of the the page life cycle (http://msdn2.microsoft.com/en-us/library/ms178472.aspx), the page asks each control for any values to contribute to viewstate (this includes your dynamically-added controls); the information is added to the viewstate tree and stored in the page in a hidden field (http://msdn2.microsoft.com/en-us/ms178198.aspx). When the page is recreated, at an early stage ASP.NET recreates the controls it knows about and matches up viewstate with the controls, which resets the controls' property values to what they were at the last rendering.

 
When you are working with dynamic controls, then, not only do you have to recreate them on each postback, but you have to do so at a point in page processing that occurs before viewstate is parsed and reset for each control. You must do this before the page's Load event. You can do it in Page_Init. Another way to do it is to override the LoadViewState method. (See next entry.)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now