state management in asp .net
Upload: baabtracom-mentoring-partner-first-programming-school-in-india
Post on 24-Dec-2014
3.654 views
DESCRIPTION
State management in ASP .NETTRANSCRIPT
![Page 1: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/1.jpg)
![Page 2: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/2.jpg)
Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
![Page 3: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/3.jpg)
Week Target Achieved
1 30 27
2 30 28
3
Typing Speed
![Page 4: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/4.jpg)
Jobs Applied# Company Designation Applied Date Current Status
1
2
3
![Page 5: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/5.jpg)
State Management
[email protected]/usernametwitter.com/usernamein.linkedin.com/in/profilenamePhonenumber
![Page 6: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/6.jpg)
Why is state necessary?
• The vast majority of Internet applications operate using the HTTP protocol.
• HTTP is state less.– This means that each request for a page is treated
as a new request by the server.
![Page 7: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/7.jpg)
Introduction to State Management
• Remember that ASP.NET is stateless– The Web server does not keep track of past client
requests• Different technologies handle the issue of
statement management differently– ASP.NET is quite unique in this regard
![Page 8: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/8.jpg)
Types of State Management
• ASP.NET offers two categories of state management– Pure client-side statement management– Server-side state management
![Page 9: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/9.jpg)
Client State Management
• View state• Control state• Hidden fields• Cookies• Query strings
![Page 10: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/10.jpg)
State Management (ViewState)
• ASP.NET preserves the state of the page’s controls between post backs by packaging and encoding it within a hidden html field.
• This view state feature can also be used programmatically to preserve additional information between post backs for the same page
Eg :- ViewState["RequestCount"] = count;int count = (int)ViewState["RequestCount"];
![Page 11: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/11.jpg)
Advantages & Disadvantage of View State
• It consumes no server memory.• It is more hidden than Query String and Hidden
Fields• Its possible to encrypt View State information.
Disadvantage :-– It increases the size of the page.
![Page 12: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/12.jpg)
State Management (ControlState)
• The ControlState property allows you to persist information as like the view state.
– The ControlState data is stored in hidden fields.
![Page 13: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/13.jpg)
Control State Application
• If we create a custom control that requires view state to work properly.
• We should use control state to ensure other developers don’t break your control by disabling view state.
![Page 14: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/14.jpg)
State Management (Hidden Fields)
• Use the HiddenField control to store persisted data.
• The data is stored in the Value property
• It’s simple and requires no server resources
![Page 15: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/15.jpg)
State Management (Query Strings)
• A query string can be used to submit data back to the same page or to another page through the URL.
Eg :-string url = "productPage.aspx?id=" + id;Response.Redirect(url);productPage.aspx int id = Convert.ToInt32(Request["id“]);
![Page 16: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/16.jpg)
Disadvantages of Query String
• Not secured (its visible completely in the address bar to the users)
• The maximum allowable length of a query string varies from browser to browser(IE only allows only 2k of url)
![Page 17: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/17.jpg)
State Management (Cookies)
• Cookies are a client-side approach for persisting state information.
• These pairs accompany both server requests and responses within the HTTP header
• Eg:-HttpCookie cookie = new HttpCookie("Name",txtName.Text);// Set expiry date to 1 day, 12 hours from nowcookie.Expires = DateTime.Now + new TimeSpan(1, 12, 0, 0);Response.Cookies.Add(cookie);
![Page 18: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/18.jpg)
Cookie Limitations• While simple, cookies have disadvantages
• A cookie can only be 4096 bytes in size
• Most browsers restrict the total number of cookies per site
• Users can refuse to accept cookies so don’t try to use them to store critical information
![Page 19: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/19.jpg)
Server State Management
• Application state• Session state
![Page 20: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/20.jpg)
Session state
• Session state is a server-based state mechanism that allows you to store data in a dictionary-style collection.
• It is scoped to the current browser session.
• That is, each user or browser session has a different session state.
![Page 21: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/21.jpg)
Example
• session[“uname”]=txt_uname.text;String uname=session[“uname”].Tostring();
![Page 22: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/22.jpg)
Application state
• Application state is a server-stored state mechanism that allows you to store global data in a dictionary-style collection that is accessible from all pages in the Web application.
![Page 23: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/23.jpg)
Application state
• Thus, application state is ideal for storing relatively small, frequently used sets of data that do not change from user-to-user or request to request.
• Eg :-Application["SiteRequestCount"] = 0;int count = (int)Application["SiteRequestCount";
![Page 24: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/24.jpg)
If this presentation helped you, please visit our page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
![Page 25: State management in ASP .NET](https://reader033.vdocument.in/reader033/viewer/2022051313/5499a559b47959a66e8b45a3/html5/thumbnails/25.jpg)
Contact Us
Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
Start up VillageEranakulam,Kerala, India.
Email: [email protected]