Frequently Asked Interview Questions

Interview Questions on ViewState ASP.NET

FAQS on ViewState Page 2
Yes, In Asp.Net you can store and retrieve data from ViewState.
Example:
//Save the text in ViewState
ViewState[“Name”] = txtFirstName.Text + txt.LastName.Text
//Retrieve the data
String name = ViewState[“Name”].ToString();
Yes

DataSet ds = new DataSet();
// write code to fill the DataSet
//Store DataSet in ViewState
ViewState["CustomerData"] = ds;
Yes, The class should be marked with [Serializable] attribute.
For Example:

[Serializable]
class Employee
{
int empId;
Public int EmployeeID
{
get { return empid; }
set {empid = value; }
}
}

//Create an object of Employee class

Employee empObj = new Employee();
empObj.EmployeeID = 1000;

//Store Employee class object in ViewState

ViewState["emp"] = empObj;

//Retrieve Employee class object from ViewState

Employee xyz = (Employee) ViewState["emp"];

Most Visited Pages

Home | Site Index | Contact Us