Store & retrieve value in viewstate - State Management System

Q.  How will you store and retrieve value in viewstate?
- Published on 28 Jul 15

a. // Storing the data in viewstate
 ViewState[“SiteName”]=”CareerRide”;
 // Retrieving Value from a View State
 Label1.Text = ViewState["SiteName "].ToString();
b. // Storing the data in viewstate
 ViewState obj=new ViewState
 ViewState [obj]=”CareerRide”;
 // Retrieving Value from a View State
 Label1.Text = ViewState[obj].ToString();
c. // Storing the data in viewstate
 ViewState=”CareerRide”;
 // Retrieving Value from a View State
 Label1.Text = ViewState.ToString();
d. None of the above.

ANSWER: // Storing the data in viewstate
 ViewState[“SiteName”]=”CareerRide”;
 // Retrieving Value from a View State
 Label1.Text = ViewState["SiteName "].ToString();
 

    Discussion

  • Raj Singh   -Posted on 30 Sep 15
    // Storing the data in viewstate
    ViewState[“SiteName”]=”CareerRide”;
    // Retrieving Value from a View State
    Label1.Text = ViewState["SiteName "].ToString();
    Viewstate works within the page only. You cannot use view state value in next page. It works as a dictionary object for storing values between multiple requests for the same page.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)