Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 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
41 active users
179 visitors today
737 pages today
how is this done?
Tools I use

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

ASP.NET Blog
RSS submissions
E-commerce

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

Tiki Statues - Tiki Masks - Tiki Totems



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?