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;
}
}
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();
}
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;
}
}
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

More Related Content

What's hot

Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
Tareq Hasan
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
Rishi Kothari
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Arulmurugan Rajaraman
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
Hitesh Santani
 
Bootstrap
BootstrapBootstrap
Bootstrap
Jadson Santos
 
jQuery
jQueryjQuery
Wrapper classes
Wrapper classes Wrapper classes
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
 
Data controls ppt
Data controls pptData controls ppt
Data controls pptIblesoft
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
WebStackAcademy
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
Ravinder Kamboj
 
Html forms
Html formsHtml forms
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
Pihu Goel
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
ShahDhruv21
 

What's hot (20)

Servlets
ServletsServlets
Servlets
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
php
phpphp
php
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
C# Delegates
C# DelegatesC# Delegates
C# Delegates
 
jQuery
jQueryjQuery
jQuery
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
ASP.NET - Life cycle of asp
ASP.NET - Life cycle of aspASP.NET - Life cycle of asp
ASP.NET - Life cycle of asp
 
Javascript event handler
Javascript event handlerJavascript event handler
Javascript event handler
 
Data controls ppt
Data controls pptData controls ppt
Data controls ppt
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
Js ppt
Js pptJs ppt
Js ppt
 
Html forms
Html formsHtml forms
Html forms
 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 

Similar to Asp.net state management

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 Part3Neeraj 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
 
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 WindowsPhoneMohammad Shaker
 
Asp.net
Asp.netAsp.net
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828Viral Patel
 
SessionTrackServlets.pptx
SessionTrackServlets.pptxSessionTrackServlets.pptx
SessionTrackServlets.pptx
Ranjeet Reddy
 
User controls
User controlsUser controls
User controlsaspnet123
 
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
 

Similar to Asp.net state management (20)

State management in asp
State management in aspState management in asp
State management in asp
 
State management in ASP.NET
State management in ASP.NETState management in ASP.NET
State management in ASP.NET
 
Javascript 2
Javascript 2Javascript 2
Javascript 2
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
 
ASP.Net Presentation Part3
ASP.Net Presentation Part3ASP.Net Presentation Part3
ASP.Net Presentation Part3
 
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
 
State management
State managementState management
State management
 
Paul Lammertsma: Account manager & sync
Paul Lammertsma: Account manager & syncPaul Lammertsma: Account manager & sync
Paul Lammertsma: Account manager & sync
 
70562 (1)
70562 (1)70562 (1)
70562 (1)
 
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
 
Asp.net
Asp.netAsp.net
Asp.net
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828
 
SessionTrackServlets.pptx
SessionTrackServlets.pptxSessionTrackServlets.pptx
SessionTrackServlets.pptx
 
User controls
User controlsUser controls
User controls
 
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
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
 
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
 
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
 
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
 
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...
 

More from 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
 
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
 

More from priya Nithya (18)

Android Architecture.pptx
Android Architecture.pptxAndroid Architecture.pptx
Android Architecture.pptx
 
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#
 
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...
 
Asynchronous data transfer
Asynchronous data transferAsynchronous data transfer
Asynchronous data transfer
 
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
 
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#
 
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
 
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
 
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
 
Adaptation of tcp window
Adaptation of tcp windowAdaptation of tcp window
Adaptation of tcp window
 
Asp.net Overview
Asp.net OverviewAsp.net Overview
Asp.net Overview
 
Key mechanism of mobile ip
Key mechanism of mobile ip Key mechanism of mobile ip
Key mechanism of mobile ip
 
Mobile ip overview
Mobile ip overviewMobile ip overview
Mobile ip overview
 
Features of mobile ip
Features of mobile ipFeatures of mobile ip
Features of mobile ip
 
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#
 
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
 
Creating simple component
Creating simple componentCreating simple component
Creating simple component
 
Internet (i mcom)
Internet (i mcom)Internet (i mcom)
Internet (i mcom)
 

Recently uploaded

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 

Recently uploaded (20)

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 

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; } }
  • 8.
  • 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(); }
  • 13.
  • 14.
  • 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; } }
  • 19.
  • 20.
  • 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"; } }