SlideShare a Scribd company logo
NITHIYAPRIYA PASAVARAJ
ASP.NET–
STATE MANAGEMENT TECHNIQUES
ASP.NET - STATEMANAGEMENT
 State Management is very important feature in
ASP.NET.
 State Management maintains & stores the information
of any user till the end of the user session.
 State management can be classified into two types.
 Client side state management
 Server side state management
Client side state management
Client side state management can
be handled by
 Hidden Fields
 View State
 Cookies
 Query String
 Control state
Server side state Management
Server side state management can
be handled by
 Session state
 Application state
Hidden Field control
 Hidden Field is a control provided by ASP.NET,
which is used to store small amount of data on the
client
 Hidden Field Control is not rendered to the browser
and it is invisible on the browser.
Syntax:
<asp: HiddenField ID=“HiddenField1”
runat=“server/>
Hidden Field Control Example
HiddenField.aspx
HiddenField.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class HiddenField : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (HiddenField1.Value != null)
{
int val = Convert.ToInt32(HiddenField1.Value) + 1;
HiddenField1.Value = val.ToString();
Label1.Text = "The Hidden Field Value is Incremented by 1 & the Current Value is : <B>" +
val.ToString() + "</B>";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Visible = true;
}
}
Asp.net state management
ViewState
 View state is used to store user’s data, which is provided by
Asp.net client side state management mechanism.
 ViewState stores data in the generated HTML using hidden
field , not on the server.
 ViewState provides page level state management.
 ie., as long as the user is on the current page, the state will be available;
Once the user redirects to the next page , the current state will be lost.
 ViewState can store any type of data & it will be enabled by
default for all the serverside control by setting true to
“EnableViewState” property.
ViewState.aspx
Viewstate.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (ViewState["count"] != null)
{
int viewstatecount = Convert.ToInt32(ViewState["count"]) + 1;
Label2.Text = viewstatecount.ToString();
ViewState["count"] = viewstatecount.ToString();
}
else
{
ViewState["count"] = "1";
}
}
}
protected void btn_Store_Click(object sender, EventArgs e)
{
ViewState["name"] = txtName.Text;
txtName.Text = "";
Label2.Text=ViewState["count"].ToString();
}
protected void btn_Display_Click(object sender, EventArgs e)
{
Label1.Text =ViewState["name"].ToString();
Label2.Text =ViewState["count"].ToString();
}
Asp.net state management
Asp.net state management
QUERYSTRING
 A Querystring is a collection of character input to a
computer or a browser.
 In Querystring , we can sent value to only desired page & the
value will be temporarily stored.
 Querystring increase the overall performance of web
application.
 When we pass content between webforms, the Querystring
followed with a separating character (?).
 The question mark(?) is, basically used for identifying data
appearing after the separating symbol.
Example : QueryHome.aspx
QueryHome.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class QueryHome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_submit_Click(object sender, EventArgs e)
{
Response.Redirect("QueryWelcome.aspx?firstname="+TextBox1.Text+
“lastname="+TextBox2.Text);
}
}
QueryWelcome.aspx
QueryWelcome.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class QueryWelcome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String firstname = Request.QueryString["firstname"];
String lastname= Request.QueryString["lastname"];
Label1.Text = "Welcome " + firstname + " " + lastname;
}
}
Asp.net state management
Asp.net state management
COOKIES
 Cookies are small piece of text which is stored on the client’s
computer by the browser.
 i.e. ., Cookies allows web applications to save user’s
information to reuse , if needed.
Cookies can be classified into 2 types
1. Persistence Cookie
2. Non-Persistence Cookie
1. Persistence Cookie
 This types of cookies are permanently stored on user hard drive.
Cookies which have an expiry date time are called persistence cookies.
 This types of cookies stored user hard drive permanently till the date time we
set.
To create persistence cookie:
Response.Cookies[“name”].Value = “Nithiyapriya”;
Response.Cookies[“Nithiyapriya”].Expires = DateTime.Now.AddMinutes(2);
(or)
HttpCookie strname = new HttpCookie(“name”);
strname.Value = “Nithiyapriya”;
strname.Expires = DateTime.Now.AddMinutes(2);
Response.Cookies.Add(strname);
Here, the Cookie Expire time is set as 2 minutes; so that we can access the
cookie values up to 2 minutes, after 2 minutes the cookies automatically
expires.
2. Non-Persistence Cookie
 This types of cookies are not permanently stored on user hard
drive.
 It stores the information up the user accessing the same browser.
 When user close the browser the cookies will be automatically
deleted.
To create non-persistence cookie:
Response.Cookies[“name”].Value = “Nithiyapriya”;
(OR)
HttpCookie strname = new HttpCookie(“name”);
strname.Value = “Nithiyapriya”;
Response.Cookies.Add(strname);
Example
Cookies.aspx
Cookies.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Cookies : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["BackgroundColor"] != null)
{
ColorSelector.SelectedValue=Request.Cookies["BackgroundColor"].Value;
BodyTag.Style["background-color"] = ColorSelector.SelectedValue;
}
}
protected void ColorSelector_SelectedIndexChanged(object sender, EventArgs e)
{
BodyTag.Style["background-color"] = ColorSelector.SelectedValue;
HttpCookie cookie = new HttpCookie("BackgroundColor");
cookie.Value = ColorSelector.SelectedValue;
cookie.Expires = DateTime.Now.AddMinutes(2);
Response.SetCookie(cookie);
}
}
This background Color of this page retains,
until 2 minutes, even after you closed the
browser.
Server side State Management
Session State
 The session is the important features of asp.net
 Session state is used to store value for the particular period of
time.
 Session can store the client data on the sever separately for
each user & it keeps value across multiple pages of website.
 i.e. user can store some information in session in one page &
it can be accessed on rest of all other pages by using session.
 For example ,When a user login to any website with
username & password, the username will be shown to all
other pages.
Syntax :
Session[“session_name”] = “session value”;
To Declare session in asp.net
Session[“name”]=”Nithiyapriya”;
Response.Redirect(“Welcomepage.aspx”);
To Retrieve session value onWelcomepage
string myvalue= Session[“name”].ToString();
Response.Write(“Name = ” + myvalue);
Example:
To set SessionTimeout add this code toWeb.config
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<sessionState timeout="1"></sessionState>
</system.web>
Login.aspx
Login.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (txtusername.Text == "admin" && txtpassword.Text == "admin")
{
Session["uname"] = txtusername.Text;
Response.Redirect("Main.aspx");
} else
{
Label1.Text = "Wrong UserName/Password";
} } }
Main.aspx
Main.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Main : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uname"] == null)
{
// Response.Redirect("Login.aspx");
Label1.Text = "Your Session is Expired";
} else
{
Label1.Text = "Welcome " + Session["uname"].ToString();
} }
protected void btn_logout_Click(object sender, EventArgs e)
{
Session["uname"] = null;
Response.Redirect("Login.aspx");
} }
After 1 Minute of Idle this
page will automatically
signed out.
Application State
 Application state is server side state management
mechanism.
 Application state is used to store data on server & shared for
all the users and it can be accessible anywhere in the
application.
 The application state is used same as session, but the
difference is, the session state is specific for a single user ;
where as an application state is common for all users.
To Store value in application state
Application[“name”] = “Nithiyapriya”;
To get value from application state
string str = Application[“name”].ToString();
 Example:
 Here we are going to calculate how many times a given page has
been visited by various clients.
Applicationstate.aspx
ApplicationState.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ApplicationState : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
int count = 0;
if (Application["visit"] != null)
{
count = Convert.ToInt32(Application["visit"].ToString());
}
count = count + 1;
Application["visit"] = count;
Label1.Text = "This page is been visited for <b> " + count.ToString() + " </b>times";
}
}
Asp.net state management
Ad

More Related Content

What's hot (20)

ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
Abhishek Sur
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Google
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.net
Deep Patel
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
ASP.NET Web form
ASP.NET Web formASP.NET Web form
ASP.NET Web form
Md. Mahedee Hasan
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
Bala Narayanan
 
ASP.NET - Life cycle of asp
ASP.NET - Life cycle of aspASP.NET - Life cycle of asp
ASP.NET - Life cycle of asp
priya Nithya
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
WebStackAcademy
 
Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
Madhuri Kavade
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
Rajkumarsoy
 
Css selectors
Css selectorsCss selectors
Css selectors
Parth Trivedi
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
Web controls
Web controlsWeb controls
Web controls
Sarthak Varshney
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
Nisa Soomro
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentals
Gopal Ji Singh
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
shreesenthil
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Taha Malampatti
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
Abhishek Sur
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Google
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.net
Deep Patel
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
ASP.NET - Life cycle of asp
ASP.NET - Life cycle of aspASP.NET - Life cycle of asp
ASP.NET - Life cycle of asp
priya Nithya
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
WebStackAcademy
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
Rajkumarsoy
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
Nisa Soomro
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentals
Gopal Ji Singh
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 

Similar to Asp.net state management (20)

State management in asp
State management in aspState management in asp
State management in asp
Ibrahim MH
 
State management in ASP.NET
State management in ASP.NETState management in ASP.NET
State management in ASP.NET
Om Vikram Thapa
 
Javascript 2
Javascript 2Javascript 2
Javascript 2
pavishkumarsingh
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
Krzysztof Szafranek
 
ASP.Net Presentation Part3
ASP.Net Presentation Part3ASP.Net Presentation Part3
ASP.Net Presentation Part3
Neeraj Mathur
 
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide showThe complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
Subhas Malik
 
State management
State managementState management
State management
Muhammad Amir
 
Paul Lammertsma: Account manager & sync
Paul Lammertsma: Account manager & syncPaul Lammertsma: Account manager & sync
Paul Lammertsma: Account manager & sync
mdevtalk
 
70562 (1)
70562 (1)70562 (1)
70562 (1)
Pragya Rastogi
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mohammad Shaker
 
Asp.net
Asp.netAsp.net
Asp.net
Yaswanth Babu Gummadivelli
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828
Viral Patel
 
SessionTrackServlets.pptx
SessionTrackServlets.pptxSessionTrackServlets.pptx
SessionTrackServlets.pptx
Ranjeet Reddy
 
User controls
User controlsUser controls
User controls
aspnet123
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
Ludmila Nesvitiy
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
Julie Iskander
 
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
JavaCro'14 - Building interactive web applications with Vaadin – Peter LehtoJavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
goodfriday
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
Mahmoud Hamed Mahmoud
 
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Dan Wahlin
 
State management in asp
State management in aspState management in asp
State management in asp
Ibrahim MH
 
State management in ASP.NET
State management in ASP.NETState management in ASP.NET
State management in ASP.NET
Om Vikram Thapa
 
ASP.Net Presentation Part3
ASP.Net Presentation Part3ASP.Net Presentation Part3
ASP.Net Presentation Part3
Neeraj Mathur
 
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide showThe complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
Subhas Malik
 
Paul Lammertsma: Account manager & sync
Paul Lammertsma: Account manager & syncPaul Lammertsma: Account manager & sync
Paul Lammertsma: Account manager & sync
mdevtalk
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mohammad Shaker
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828
Viral Patel
 
SessionTrackServlets.pptx
SessionTrackServlets.pptxSessionTrackServlets.pptx
SessionTrackServlets.pptx
Ranjeet Reddy
 
User controls
User controlsUser controls
User controls
aspnet123
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
Ludmila Nesvitiy
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
goodfriday
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
Mahmoud Hamed Mahmoud
 
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Dan Wahlin
 
Ad

More from priya Nithya (18)

Android Architecture.pptx
Android Architecture.pptxAndroid Architecture.pptx
Android Architecture.pptx
priya Nithya
 
Html server control - ASP. NET with c#
Html server control - ASP. NET with c#Html server control - ASP. NET with c#
Html server control - ASP. NET with c#
priya Nithya
 
Modes of transfer - Computer Organization & Architecture - Nithiyapriya Pasav...
Modes of transfer - Computer Organization & Architecture - Nithiyapriya Pasav...Modes of transfer - Computer Organization & Architecture - Nithiyapriya Pasav...
Modes of transfer - Computer Organization & Architecture - Nithiyapriya Pasav...
priya Nithya
 
Asynchronous data transfer
Asynchronous data transferAsynchronous data transfer
Asynchronous data transfer
priya Nithya
 
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LABHTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
priya Nithya
 
HTML SERVER CONTROL - ASP.NET WITH C#
HTML SERVER CONTROL  - ASP.NET WITH C#HTML SERVER CONTROL  - ASP.NET WITH C#
HTML SERVER CONTROL - ASP.NET WITH C#
priya Nithya
 
Android LAb - Creating an android app with Radio button
Android LAb - Creating an android app with Radio buttonAndroid LAb - Creating an android app with Radio button
Android LAb - Creating an android app with Radio button
priya Nithya
 
Web application using c# Lab - Web Configuration file
Web application using c# Lab - Web Configuration fileWeb application using c# Lab - Web Configuration file
Web application using c# Lab - Web Configuration file
priya Nithya
 
Creation of simple application using - step by step
Creation of simple application using - step by stepCreation of simple application using - step by step
Creation of simple application using - step by step
priya Nithya
 
Adaptation of tcp window
Adaptation of tcp windowAdaptation of tcp window
Adaptation of tcp window
priya Nithya
 
Asp.net Overview
Asp.net OverviewAsp.net Overview
Asp.net Overview
priya Nithya
 
Key mechanism of mobile ip
Key mechanism of mobile ip Key mechanism of mobile ip
Key mechanism of mobile ip
priya Nithya
 
Mobile ip overview
Mobile ip overviewMobile ip overview
Mobile ip overview
priya Nithya
 
Features of mobile ip
Features of mobile ipFeatures of mobile ip
Features of mobile ip
priya Nithya
 
Creating a Name seperator Custom Control using C#
Creating a Name seperator Custom Control using C#Creating a Name seperator Custom Control using C#
Creating a Name seperator Custom Control using C#
priya Nithya
 
How to Create Database component -Enterprise Application Using C# Lab
How to Create Database component -Enterprise Application Using C# Lab  How to Create Database component -Enterprise Application Using C# Lab
How to Create Database component -Enterprise Application Using C# Lab
priya Nithya
 
Creating simple component
Creating simple componentCreating simple component
Creating simple component
priya Nithya
 
Internet (i mcom)
Internet (i mcom)Internet (i mcom)
Internet (i mcom)
priya Nithya
 
Android Architecture.pptx
Android Architecture.pptxAndroid Architecture.pptx
Android Architecture.pptx
priya Nithya
 
Html server control - ASP. NET with c#
Html server control - ASP. NET with c#Html server control - ASP. NET with c#
Html server control - ASP. NET with c#
priya Nithya
 
Modes of transfer - Computer Organization & Architecture - Nithiyapriya Pasav...
Modes of transfer - Computer Organization & Architecture - Nithiyapriya Pasav...Modes of transfer - Computer Organization & Architecture - Nithiyapriya Pasav...
Modes of transfer - Computer Organization & Architecture - Nithiyapriya Pasav...
priya Nithya
 
Asynchronous data transfer
Asynchronous data transferAsynchronous data transfer
Asynchronous data transfer
priya Nithya
 
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LABHTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
priya Nithya
 
HTML SERVER CONTROL - ASP.NET WITH C#
HTML SERVER CONTROL  - ASP.NET WITH C#HTML SERVER CONTROL  - ASP.NET WITH C#
HTML SERVER CONTROL - ASP.NET WITH C#
priya Nithya
 
Android LAb - Creating an android app with Radio button
Android LAb - Creating an android app with Radio buttonAndroid LAb - Creating an android app with Radio button
Android LAb - Creating an android app with Radio button
priya Nithya
 
Web application using c# Lab - Web Configuration file
Web application using c# Lab - Web Configuration fileWeb application using c# Lab - Web Configuration file
Web application using c# Lab - Web Configuration file
priya Nithya
 
Creation of simple application using - step by step
Creation of simple application using - step by stepCreation of simple application using - step by step
Creation of simple application using - step by step
priya Nithya
 
Adaptation of tcp window
Adaptation of tcp windowAdaptation of tcp window
Adaptation of tcp window
priya Nithya
 
Key mechanism of mobile ip
Key mechanism of mobile ip Key mechanism of mobile ip
Key mechanism of mobile ip
priya Nithya
 
Mobile ip overview
Mobile ip overviewMobile ip overview
Mobile ip overview
priya Nithya
 
Features of mobile ip
Features of mobile ipFeatures of mobile ip
Features of mobile ip
priya Nithya
 
Creating a Name seperator Custom Control using C#
Creating a Name seperator Custom Control using C#Creating a Name seperator Custom Control using C#
Creating a Name seperator Custom Control using C#
priya Nithya
 
How to Create Database component -Enterprise Application Using C# Lab
How to Create Database component -Enterprise Application Using C# Lab  How to Create Database component -Enterprise Application Using C# Lab
How to Create Database component -Enterprise Application Using C# Lab
priya Nithya
 
Creating simple component
Creating simple componentCreating simple component
Creating simple component
priya Nithya
 
Ad

Recently uploaded (20)

High Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptxHigh Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptx
Ayush Srivastava
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Timber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptxTimber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptx
Tantish QS, UTM
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Diabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomicDiabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomic
Pankaj Patawari
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
High Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptxHigh Performance Liquid Chromatography .pptx
High Performance Liquid Chromatography .pptx
Ayush Srivastava
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Timber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptxTimber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptx
Tantish QS, UTM
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Diabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomicDiabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomic
Pankaj Patawari
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 

Asp.net state management

  • 2. ASP.NET - STATEMANAGEMENT  State Management is very important feature in ASP.NET.  State Management maintains & stores the information of any user till the end of the user session.  State management can be classified into two types.  Client side state management  Server side state management
  • 3. Client side state management Client side state management can be handled by  Hidden Fields  View State  Cookies  Query String  Control state
  • 4. Server side state Management Server side state management can be handled by  Session state  Application state
  • 5. Hidden Field control  Hidden Field is a control provided by ASP.NET, which is used to store small amount of data on the client  Hidden Field Control is not rendered to the browser and it is invisible on the browser. Syntax: <asp: HiddenField ID=“HiddenField1” runat=“server/>
  • 6. Hidden Field Control Example HiddenField.aspx
  • 7. HiddenField.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class HiddenField : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (HiddenField1.Value != null) { int val = Convert.ToInt32(HiddenField1.Value) + 1; HiddenField1.Value = val.ToString(); Label1.Text = "The Hidden Field Value is Incremented by 1 & the Current Value is : <B>" + val.ToString() + "</B>"; } } protected void Button1_Click(object sender, EventArgs e) { Label1.Visible = true; } }
  • 9. ViewState  View state is used to store user’s data, which is provided by Asp.net client side state management mechanism.  ViewState stores data in the generated HTML using hidden field , not on the server.  ViewState provides page level state management.  ie., as long as the user is on the current page, the state will be available; Once the user redirects to the next page , the current state will be lost.  ViewState can store any type of data & it will be enabled by default for all the serverside control by setting true to “EnableViewState” property.
  • 11. Viewstate.aspx.cs protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { if (ViewState["count"] != null) { int viewstatecount = Convert.ToInt32(ViewState["count"]) + 1; Label2.Text = viewstatecount.ToString(); ViewState["count"] = viewstatecount.ToString(); } else { ViewState["count"] = "1"; } } }
  • 12. protected void btn_Store_Click(object sender, EventArgs e) { ViewState["name"] = txtName.Text; txtName.Text = ""; Label2.Text=ViewState["count"].ToString(); } protected void btn_Display_Click(object sender, EventArgs e) { Label1.Text =ViewState["name"].ToString(); Label2.Text =ViewState["count"].ToString(); }
  • 15. QUERYSTRING  A Querystring is a collection of character input to a computer or a browser.  In Querystring , we can sent value to only desired page & the value will be temporarily stored.  Querystring increase the overall performance of web application.  When we pass content between webforms, the Querystring followed with a separating character (?).  The question mark(?) is, basically used for identifying data appearing after the separating symbol.
  • 17. QueryHome.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class QueryHome : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btn_submit_Click(object sender, EventArgs e) { Response.Redirect("QueryWelcome.aspx?firstname="+TextBox1.Text+ “lastname="+TextBox2.Text); } }
  • 18. QueryWelcome.aspx QueryWelcome.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class QueryWelcome : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { String firstname = Request.QueryString["firstname"]; String lastname= Request.QueryString["lastname"]; Label1.Text = "Welcome " + firstname + " " + lastname; } }
  • 21. COOKIES  Cookies are small piece of text which is stored on the client’s computer by the browser.  i.e. ., Cookies allows web applications to save user’s information to reuse , if needed. Cookies can be classified into 2 types 1. Persistence Cookie 2. Non-Persistence Cookie
  • 22. 1. Persistence Cookie  This types of cookies are permanently stored on user hard drive. Cookies which have an expiry date time are called persistence cookies.  This types of cookies stored user hard drive permanently till the date time we set. To create persistence cookie: Response.Cookies[“name”].Value = “Nithiyapriya”; Response.Cookies[“Nithiyapriya”].Expires = DateTime.Now.AddMinutes(2); (or) HttpCookie strname = new HttpCookie(“name”); strname.Value = “Nithiyapriya”; strname.Expires = DateTime.Now.AddMinutes(2); Response.Cookies.Add(strname); Here, the Cookie Expire time is set as 2 minutes; so that we can access the cookie values up to 2 minutes, after 2 minutes the cookies automatically expires.
  • 23. 2. Non-Persistence Cookie  This types of cookies are not permanently stored on user hard drive.  It stores the information up the user accessing the same browser.  When user close the browser the cookies will be automatically deleted. To create non-persistence cookie: Response.Cookies[“name”].Value = “Nithiyapriya”; (OR) HttpCookie strname = new HttpCookie(“name”); strname.Value = “Nithiyapriya”; Response.Cookies.Add(strname);
  • 25. Cookies.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Cookies : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["BackgroundColor"] != null) { ColorSelector.SelectedValue=Request.Cookies["BackgroundColor"].Value; BodyTag.Style["background-color"] = ColorSelector.SelectedValue; } } protected void ColorSelector_SelectedIndexChanged(object sender, EventArgs e) { BodyTag.Style["background-color"] = ColorSelector.SelectedValue; HttpCookie cookie = new HttpCookie("BackgroundColor"); cookie.Value = ColorSelector.SelectedValue; cookie.Expires = DateTime.Now.AddMinutes(2); Response.SetCookie(cookie); } }
  • 26. This background Color of this page retains, until 2 minutes, even after you closed the browser.
  • 27. Server side State Management Session State  The session is the important features of asp.net  Session state is used to store value for the particular period of time.  Session can store the client data on the sever separately for each user & it keeps value across multiple pages of website.  i.e. user can store some information in session in one page & it can be accessed on rest of all other pages by using session.  For example ,When a user login to any website with username & password, the username will be shown to all other pages.
  • 28. Syntax : Session[“session_name”] = “session value”; To Declare session in asp.net Session[“name”]=”Nithiyapriya”; Response.Redirect(“Welcomepage.aspx”); To Retrieve session value onWelcomepage string myvalue= Session[“name”].ToString(); Response.Write(“Name = ” + myvalue); Example: To set SessionTimeout add this code toWeb.config <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> <sessionState timeout="1"></sessionState> </system.web>
  • 29. Login.aspx Login.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { if (txtusername.Text == "admin" && txtpassword.Text == "admin") { Session["uname"] = txtusername.Text; Response.Redirect("Main.aspx"); } else { Label1.Text = "Wrong UserName/Password"; } } }
  • 30. Main.aspx Main.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Main : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Session["uname"] == null) { // Response.Redirect("Login.aspx"); Label1.Text = "Your Session is Expired"; } else { Label1.Text = "Welcome " + Session["uname"].ToString(); } } protected void btn_logout_Click(object sender, EventArgs e) { Session["uname"] = null; Response.Redirect("Login.aspx"); } }
  • 31. After 1 Minute of Idle this page will automatically signed out.
  • 32. Application State  Application state is server side state management mechanism.  Application state is used to store data on server & shared for all the users and it can be accessible anywhere in the application.  The application state is used same as session, but the difference is, the session state is specific for a single user ; where as an application state is common for all users.
  • 33. To Store value in application state Application[“name”] = “Nithiyapriya”; To get value from application state string str = Application[“name”].ToString();  Example:  Here we are going to calculate how many times a given page has been visited by various clients.
  • 35. ApplicationState.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class ApplicationState : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click1(object sender, EventArgs e) { int count = 0; if (Application["visit"] != null) { count = Convert.ToInt32(Application["visit"].ToString()); } count = count + 1; Application["visit"] = count; Label1.Text = "This page is been visited for <b> " + count.ToString() + " </b>times"; } }