State management is the process to maintain state and page information over multiple requests for the same or different pages. Web applications are based on stateless HTTP protocol so web form pages do not automatically indicate whether the requests in a sequence are all from the same client or even whether a single browser instance is still actively viewing a page or site. A new instance of the Web page class is created each time the page is requested and with each round trip to the server pages are destroyed and re-created.
ASP.NET includes several options that help to preserve data on both a per-page basis and an application-wide basis.
Client-Side
Method State Management
1. View state 2.Control state 3.Hidden fields 4.Cookies 5. Query string
Server-Side
Method State Management
1. Application state 2.Session state 3.Profile properties 4. Database support
State management in Silverlight 2 can be done using the concept of Isolated storage. In Silverlight application everything is compiled in one XAP file and when a user requests this is copied to the client machine. So there are no server round trips and page request every time, this reduces the need of maintaining the use or application state. But in typical business application state management may be required.
Silverlight
Isolated Storage
Isolated storage is a data storage mechanism that helps in storing data on the client machine in a hidden folder outside the browser’s cache. Silverlight Applications runs as partial trust but isolated storage API is allowed to create and access files that are stored in an Isolated Storage area which act as non volatile cache and is shared across the browsers. Every application has its own portion of the isolated storage with a default size of 1MB and can be used to store user specific information as name, preferences and skins etc. It can be used as Client-Side state management.
Location of Isolated
Storage in
Vista
%:\Users\%\AppData\LocalLow\Microsoft\Silverlight\is
Location of Isolated
Storage in Windows XP
%:\Documents and Settings\%\Local
Settings\Application Data\Microsoft\Silverlight\is
Retrieve
Isolated Storage Information (Quota, Available Space)
private void ButtonShowInfo_Click(object sender, RoutedEventArgs e)
{
try
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
string spaceUsed = (store.Quota -
store.AvailableFreeSpace).ToString();
string spaceAvailable =
store.AvailableFreeSpace.ToString();
string currentQuota =
store.Quota.ToString();
string message = String.Format("Quota:
{0} bytes, Used: {1} bytes, Available: {2} bytes", currentQuota,
spaceUsed, spaceAvailable);
TextBoxResults.Text = message;
SaveLogToIsolatedStorage(message);
}
}
catch (IsolatedStorageException)
{
TextBoxResults.Text = "Unable to access
Isolated Storage.";
SaveLogToIsolatedStorage("Unable to access
Isolated Storage.");
}
}
Create a
variable for IsolatedStorageSettings
//Create
a variable for IsolatedStorageSettings
//IsolatedStorageSettings
contains the contents of the application IsolatedStorageFile scoped at the
application level
private IsolatedStorageSettings isoStorSettings = IsolatedStorageSettings.ApplicationSettings;
Save
information in Isolated Storage
private void ButtonSave_Click(object sender, RoutedEventArgs e)
{
try
{
User user = new User();
user.Name = TextBoxName.Text;
user.Designation = TextBoxDesignation.Text;
user.Address = TextBoxAddress.Text;
user.City = TextBoxCity.Text;
isoStorSettings.Add("UserDetail",
user);
TextBoxResults.Text = "User Detaild
stored.";
SaveLogToIsolatedStorage("User Detaild
stored.");
}
catch (ArgumentException ex)
{
TextBoxResults.Text = ex.Message;
SaveLogToIsolatedStorage(ex.Message);
}
}
Retrieve information from Isolated Storage
private void ButtonRetrieve_Click(object sender, RoutedEventArgs e)
{
try
{
User user = (User)isoStorSettings["UserDetail"];
TextBoxName.Text = user.Name;
TextBoxDesignation.Text = user.Designation;
TextBoxAddress.Text = user.Address;
TextBoxCity.Text = user.City;
TextBoxResults.Text = "User Details
retrieved.";
SaveLogToIsolatedStorage("User Details
retrieved.");
}
catch (System.Collections.Generic.KeyNotFoundException ex)
{
TextBoxResults.Text = ex.Message;
SaveLogToIsolatedStorage(ex.Message);
ClearTextBoxes();
}
}
Delete from
Isolated Storage
private void ButtonDelete_Click(object sender, RoutedEventArgs e)
{
isoStorSettings.Remove("UserDetail");
TextBoxResults.Text = "User Detaild
deleted.";
SaveLogToIsolatedStorage("User Detaild
deleted.");
ClearTextBoxes();
}
Increase the
Isolated Storage space
private void ButtonIncreaseAllocation_Click(object sender, RoutedEventArgs e)
{
try
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
// Request more space in
bytes.

prabaPosted Jan 20, 2011, 11:42 AM
Is it possible to get the application resources from one application to another application using adding reference from one application to another application? When page refreshes, is it possible to get the updated application resources.