Why Microsoft introduce state management techniques?
Generally, every system uses HTTP protocol it is stateless protocol.It does not maintaining the status to client.But,we are maintaining some status to client .HTTP protocol does not retain any information about user requests.it is difficult way to create communication between server and client, page is created each time the page is requested. For example, if a user enters any information into a text box, that information would be lost in the round trip from the browser or client device to the server.So,Microsoft introduced state management techniques.
What is state management techniques?
State management techniques means to maintaining the status either client side or serverside.These are 2 types
1) Client-side State management techniques
2) Server-side State management techniques
Client side State management
It means,to maintaining the client information in client side.These are different types
Cookie
View State:
Query strings:
Hidden fields:
Cookie: A cookie is a small piece of data stored on user's computer. Usually,these information is stored either web browser or hard disk. Cookies are used by websites to keep track of visitors. Every time a user visits a website, cookies are retrieved from user machine and help identify the user. So,it does not provide any security to user information.
Example:
if (Request.Cookies["id"] != null)
Lable1.Text = "Hello" + Request.Cookies["id"].Value +";
else
Lable1.Text = "hi";
View State: View State can be used to stores information in client side.
Example:
ViewState["id"] = "welcome";
Response.Write(ViewState["id"]);
Query strings: Query strings are usually used to send information from one page to another page.
http://www.bestsavings.in/gk/java.html?id=2&page=1
Hidden fields: Hidden fields are used to store data at the page level. As its name says, these fields are not rendered by the browser. It's just like a standard control for which you can set its properties. Whenever a page is submitted to server, hidden fields values are also posted to server along with other controls on the page.
Example:
Hidden1.Value="welcome";
string str=Hidden1.Value;
Server Side State management
It means,to maintaining the client information in server side.These are different types
Sessions
Application Status
Session: Session state is similar to application state, except that it is scoped to the current browser session. If different users are using your application, each user session will have a different session state. In addition, if a user leaves your application and then returns later, the second user session will have a different session state from the first.Session state is structured as a key/value dictionary for storing session-specific information that needs to be maintained between server round trips and between requests for pages.
Example:
Session["id"]=TextBox1.Text;
Lable1.Text=session["id"].ToString();
Application status: Application object is used to store data which is visible across entire application and shared across multiple user sessions. Data which needs to be persisted for entire life of application should be stored in application object.
Example:
Application.Lock();
Application["id"]="welcome";
Application.UnLock();
No comments:
Post a Comment