ASP/.NET Web Hosting
* 3 Months FREE *
CLICK HERE!
 CoverYourASP --> Application variables --> Part 2

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
170 active users
10241 visitors today
11079 pages today
how is this done?
ASP.NET Showcase
ASP.NET Graph and Chart Component with FREE developer version

ASP.NET Shopping Cart and E-commerce Control with FREE trial download

ASP.NET Web Hosting with free month and setup

$15 Domain Name Registration from .DNR.
As seen on these sites
Special thanks go to the sites that support me by publishing my articles.
See more

CoverYourASP
Copyright © 1999-2008 James Shaw.
All rights reserved.

ASP.NET Blog
ASPRSS
ShawThing

Now open source with SourceForge!

A simple function to store HTML

In the earlier example of populating a list box from a recordset I created a function to execute the query, and store the HTML in Application variables for easy and very efficient re-use:

// ============================================
// put infrequently changing data into application variables
// ============================================
function GetListFromApp ( sSQL, sName)
{
   var sHTML;

   // connect to database
   DBInitConnection ( );

   // get HTML from Application variable
   // and if empty...
   if ( ! ( sHTML = Application ( sName ) ) )
   {
      //...get records from database
      DBGetRecords ( sSQL );

      // make up HTML <select> tag
      sHTML = '<select name="' +sName + '">';

      while ( !oRecordSet.EOF )
      {
         sHTML += '<option>' + oRecordSet ( 0 ) + '</option>';      
         oRecordSet.moveNext ( );
      }

      sHTML += '</select>';

      // set the Application variable
      Application ( sName ) = sHTML;
   }

   // release database connection
   DBReleaseConnection ( );

   return sHTML;
}

To use it to store a list box containing all your professors names, do this:

// form tag posting to itself
Response.Write ( '<form action="' + Request.ServerVariables ( 'SCRIPT_NAME' ) + '" method="post">' );

// a list box containing professors - only
// does database query once
Response.Write ( 'Department code: ' + GetListFromApp ( 'SELECT Name FROM Professors', 'prof' ) );

Part 3: Counting visits and page views...

Featured sponsor
My favorite resources

Selling products online - read how James does it now



Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?