One of the difficulties of Web programming is that it takes place in a stateless environment. That is, information that is generated on one page is not normally accessible by any other page. When navigating from one page to the next, all knowledge of the previous page is lost. Neither the browser nor the server retains any information associated with the previous page. Each page access occurs as if it were the first time it has ever happened. Since the processing "states" of Web pages are not normally maintained between page navigations, it introduces difficulties in coordinating processing work between pages; thus, the introduction in ASP.NET of View States, Sessions, and other methods to "maintain state" between pages.
This problem of sharing information between pages of a Web site has been attacked in several ways in the past. Browser cookies are one way of saving information from one page to make it accessible by another page. Small amounts of data can be written from a page to a cookie file on the local computer and then retrieved from that same computer by a different page. However, cookies are limited in the amount of information that can be saved to the browser for later retrieval.
Also, appending query strings to URL addresses can be used to pass information between pages. You probably have noticed these query strings in your meanderings around the Web, although you might not have known what they were for. Below, for example, is a URL with a query string attached that was encountered while browsing the Web. A query string is the string of characters following a question mark (?) appended to a URL. It passes along information needed by the destination page to accomplish its processing.
You will have occasion to use query strings for certain ASP.NET applications. Still, there are practical limits on how much information can be contained in a query string for passing between pages.
In a similar way, Web forms have been used to collect information on one page to pass along to a second page, often through "hidden" fields of data and control information. Although form submission is the primary technique for gathering user data for processing, it involves extra, and often times unnecessary, coding overhead to simply maintain state between pages.
Another method of maintaining the state of information between pages is to write it to files and databases. One page can create a data store on the server for retrieval and use by any other page. Although databases play a large and significant role in ASP.NET processing, they are not very practical for maintaining the usually simple states of affairs needed for Web pages to communicate with one another. They may be over-kill for the need to pass a few data values from one page to the next.
Because of the various limitations of browser cookies, query strings, form submissions, and databases for maintaining state between pages, the ASP.NET environment introduces ViewState and Session variables. Data values, whether they be user data or processing control information, can be assigned to these variables for carry forward between pages, maintaining state in a stateless environment. They are primary techniques to integrate processing among individual, independent, isolated, and really stupid Web pages with no memory of things past.
ASP.Net Stateless Web
Hot on Web: