Click here to Skip to main content
15,895,667 members
Articles / Web Development / HTML

Context Sensitive Help using Client Callbacks - AJAX Style

Rate me:
Please Sign up or sign in to vote.
3.62/5 (8 votes)
25 Sep 20068 min read 39.6K   35  
This article is all about providing Context Sensitive Help in a web page, asynchronously or AJAX style, using Client Callbacks in .NET 2.0.
/*
 * Cache Management Class
 * ==============================================================
 * Creator 			Ch.V.L.Mahendra
 * Created			17-Sep-2006
 * Environments		IIS 5.*, IIS 6.0, .Net Framework 2.0
 * Description 
 *
 * Responsible for managing the application cache. If cache
 * elements need updating, this class fetches information to
 * populate them from the database or XML file as applicable.
 *
 * Change Log
 * ==============================================================
 * Version	Date		Author		    Changes
 * 0.1		17-Sep-2006	Ch.V.L.Mahendra	Created
 */

using System;
using System.Web.Caching;
using System.Collections;
using System.Xml;
using ContextSensitiveHelp.Pages.Xml;

namespace ContextSensitiveHelp.Pages.Common
{
    /// <summary>
    /// Manages the application cache, and populates it if neccessary.
    /// </summary>
    public class CacheManager
    {
        #region Private Variables
        /// <summary>
        /// The cache object to hold the data.
        /// </summary>
        private Cache objApplicationCache;
        /// <summary>
        /// Variable to hold the status of the data in the Cache.
        /// </summary>
        private bool blnRefreshed;

        #endregion 

        #region Properties

        /// <summary>
        /// Value indicating whether cache has been refreshed in this instance
        /// </summary>
        public bool IsRefreshed
        {
            get
            {
                return blnRefreshed;
            }
            set
            {
                blnRefreshed = value;
            }
        }

        #endregion 

        #region Private Methods
             
        #region Method to Refresh the Messages Xml

        /// <summary>
        /// Refreshes the application error messages into the application cache.
        /// </summary>
        private void RefreshMessages()
        {
            /* load the XML error file into memory */
            XmlDocument objDocument = new XmlDocument();
            objDocument.Load(XmlMessage.XmlFile);
            objApplicationCache.Insert("appMessages", objDocument, new CacheDependency(XmlMessage.XmlFile));
            this.IsRefreshed = true;
        }

        #endregion 

        #endregion

        #region Public Methods

        #region Constructor Logic

        /// <summary>
        /// Constructor for the cache manager, checks that the
        /// lookup table has been cached by the application.
        /// </summary>
        /// <param name="objCache">The application's cache object</param>
        public CacheManager(Cache objCache)
        {
            objApplicationCache = objCache;
            this.IsRefreshed = false;
        }

        #endregion 
        
                  
        #region Method to load the Messages Xml

        /// <summary>
        /// Load the application help messages from the cache
        /// </summary>
        public void LoadMessages()
        {
            if (objApplicationCache["appMessages"] == null)
                RefreshMessages();

            XmlMessage.Xml = (XmlDocument)objApplicationCache["appMessages"];
        }

        #endregion 
      
        #endregion

    }
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions