Other Types of State Management


Other Types of "State Management"

In thinking about what state and/or cache management really is, you can come to the point of looking at it as just a way to preserve data between each HTTP request. If you ignore for a moment the opportunities to persist and expire data (features made available by true state management approaches), you can entertain the idea of there being a few other "data preservation" techniques provided by ASP.NET.

Rightly so, these approaches are not acknowledged as official state or cache management choices. Nevertheless, it may be useful to be familiar with a few addi tional ways to preserve data between HTTP requests . With a slight stretch of definition, I suggest that these approaches do represent a type of state man agement . The additional approaches are as follows :

  • Storing server controls in the Form variables via the Request object

  • Storing all HTML and text in the LiteralControl via the Page object

  • Storing data in the HashTable collection via the Context object

Form Variables via the Request Object

The Request object ( System.Web.HttpRequest ) exposes the Form property. Using this property, you can easily access a key/value collection called the form vari ables. What are form variables? Basically, form variables collectively represent all of the <Input></Input> type of controls that are on the Web Form. In other words, the server controls (e.g., TextBox, Button, Hidden, and so on) that render as HTML <Input> tags are included in this form variables key/value collection.

For example, a TextBox server control that is defined in the .aspx file with an "id" value of Textbox1 will appear in the form variable collection with a key of Textbox1 . The value of the TextBox's Text property will be accessible in the form variable collection. The form variables are populated automatically and stored in the Request object as it is sent from the client back to the server.

LiteralControl via the Page Object

In Chapter 14 in the section "Controls, Controls, Controls, and More Controls," I introduced and described the LiteralControl class. You understand now that ASP.NET uses the LiteralControl class to store and retrieve all "text"-based data (e.g., the rendered HTML elements) between each HTTP request. In other words, the LiteralControl class is used for the preservation of data ” yes, another type of state management.

Using the Page object, take a look at the Controls property. You will see a few controls stored in the ControlCollection type collection. One of these controls is the LiteralControl that ASP.NET automatically creates for you. Optionally, you can create and populate your own LiteralControl control in server-side code. Of course, you would only seek to take advantage of this technique when looking for alternative approaches to data preservation.

Note  

I realize the phrase "controls stored in the ControlCollection type collection" sounds a bit redundant. However, once you get to the point of being able to digest a phrase like "the LiteralControl control, not to be confused with the Literal control," all the rest becomes quite easy. Again, I discussed these two controls in Chapter 14 in the section "Controls, Controls, Controls, and More Controls" ”literally.

HashTable Collection via the Context Object

The Context object ( System.Web.HttpContext ) exposes an Items property. This particular Items property provides a key/value collection using the IDictionary interface. Several classes, one of which is the HashTable , implement the IDictionary interface . It is the HashTable class that will actually hold the key/value pairs and provide the type of data preservation resembling state management.

You will recall that the Context object encompasses an entire HTTP request and all of the objects associated with the HTTP request. Once you programmati cally establish a reference to the current context, you have access to the HashTable key/value collection in question.

According to Microsoft's documentation, this key/value collection serves the purpose of "organizing and sharing data between an IHttpModule and an IHttpHandler." Now, "organizing and sharing data" sounds a lot like state man agement to me. What do you think?

Cross-Reference  

See the earlier sidebar titled "Handlers, Modules, and Application-Level Events" for further explanation of the IHttpModule and IHttpHandler interfaces.




COBOL and Visual Basic on .NET
COBOL and Visual Basic on .NET: A Guide for the Reformed Mainframe Programmer
ISBN: 1590590481
EAN: 2147483647
Year: 2003
Pages: 204

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net