Click here to Skip to main content
12,632,234 members (26,165 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads

Tagged as

Stats

429.4K views
3.2K downloads
79 bookmarked
Posted

State Management in ASP.NET - Introduction

, 20 Jan 2014 CPOL
An overview of state management techniques in ASP.NET.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class sessionDemo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["Count"] != null) //Lets retrieve, increase and store again
        {
            Label3.Text = Request.QueryString["Count"];
        }
       
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        
        
        int noOfRedirection = 0;

        if (Request.QueryString["Count"] != null) //Lets retrieve, increase and store again
        {
            noOfRedirection = Convert.ToInt32(Request.QueryString["Count"]) + 1;
        }
        else //First postback, lets store the info
        {
            noOfRedirection = 1;
        }

        Response.Redirect("sessionApplicationDemo.aspx?Count=" + noOfRedirection);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Application.Lock();
        Application["Count"] = Convert.ToInt32(Application["Count"]) + 1;
        Application.UnLock();
        Label1.Text = Application["Count"].ToString();

        //Store in Session State --------------------------------------------------------------          
        Session["Count"] = Convert.ToInt32(Session["Count"]) + 1;
        Label2.Text = Session["Count"].ToString();

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sachin Gargava
Software Developer (Senior)
India India
He has done Master Degree in Computer Application (MCA) and currently working as a Sr. Software Engineer and having more than 6+ years exp. He has worked with all the .NET framework and good exposure in Web and Windows based development using Microsoft Technology.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161208.2 | Last Updated 20 Jan 2014
Article Copyright 2012 by Sachin Gargava
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid