Click here to Skip to main content
15,867,488 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.4K   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.
/*
 * Xml Messages Class
 * ==============================================================
 * Creator 			Ch.V.L.Mahendra
 * Created			17-Sep-2006
 * Environments		IIS 5.*, IIS 6.0, .Net Framework 2.0
 * Description 
 *
 * Provides an interface to the XML Messages file.
 *
 * Change Log
 * ==============================================================
 * Version	Date		Author		    Changes
 * 0.1		17-Sep-2006	Ch.V.L.Mahendra	Created
 */

using System;
using System.Xml;
using System.Data;
using System.Text;
using System.Collections;

namespace ContextSensitiveHelp.Pages.Xml
{
    /// <summary>
    /// Class to manage the xml messages from the xml file.
    /// </summary>
    public class XmlMessage
    {
        #region Private Variables

        /// <summary>
        /// Variable to hold the path of the Xml file
        /// </summary>
        private static string strXmlFilePath;
        /// <summary>
        /// Variable to hold the Xml Document
        /// </summary>
        private static XmlDocument objDocument;

        #endregion 

        #region Public Methods

        /// <summary>
        /// Returns the requested message from the xml file.
        /// </summary>
        /// <param name="strReference">The reference number for the message</param>
        /// <returns>A message entry structure holding the message information</returns>
        public static MessageEntry GetMessageEntry(string strReference)
        {
            XmlNode objTitle;
            XmlNode objMessage;
            XmlNodeList objNodeList;
            
            objNodeList = XmlMessage.GetNodes("/messages/entry[@ref='" + strReference + "']/title");            
            if (objNodeList.Count == 0) return new MessageEntry(strReference, "There has been an error in the application. No supporting information is available for this error.", "Unknown Error");            
            objTitle = objNodeList[0];
            objNodeList = XmlMessage.GetNodes("/messages/entry[@ref='" + strReference + "']/message");
            if (objNodeList.Count == 0) return new MessageEntry(strReference, "There has been an error in the application. No supporting information is available for this error.", "Unknown Error");            
            objMessage = objNodeList[0];            
            return new MessageEntry(strReference, objMessage.InnerText, objTitle.InnerText);
        }

        /// <summary>
        /// Returns messages relating to the context
        /// </summary>
        /// <param name="strContext">The context to get messages for</param>
        /// <returns>An xml node list of structures</returns>
        public static XmlNodeList GetContextHelp(string strContext)
        {
            XmlNodeList objNodeList = XmlMessage.GetNodes("/messages/entry[@context='" + strContext + "']");
            return objNodeList;
        }  

        /// <summary>
        /// Fetch a node list for the requested XPath query.
        /// </summary>
        /// <param name="strXPath">Specifies the criteria for the nodes to return</param>
        /// <returns>A node list of the elements it contains</returns>
        public static XmlNodeList GetNodes(string strXPath)
        {            
            XmlElement objRoot = objDocument.DocumentElement;            
            
            return objRoot.SelectNodes(strXPath);
        }

        #endregion

        #region Properties

        /// <summary>
        /// The absolute file path of the Xml file being read.
        /// </summary>
        public static string XmlFile
        {
            get
            {
                return strXmlFilePath;
            }
            set
            {
                strXmlFilePath = value;
            }
        }

        /// <summary>
        /// Returns the Xml document object of the Xml settings file.
        /// </summary>
        public static XmlDocument Xml
        {
            get
            {
                return objDocument;
            }
            set
            {
                objDocument = value;
            }
        }

        #endregion 
    }

    #region Struct

    /// <summary>
    /// Structure to hold the content of an xml message.
    /// </summary>
    public struct MessageEntry
    {
        /// <summary>
        /// The reference for the message
        /// </summary>
        public string Reference;
        /// <summary>
        /// The content for the message
        /// </summary>
        public string Message;
        /// <summary>
        /// The title for the message
        /// </summary>
        public string Title;

        /// <summary>
        /// Constructor for the message. 
        /// </summary>
        /// <param name="strReference">Reference value for this message</param>
        /// <param name="strMessage">Content of the message</param>
        /// <param name="strTitle">Title of the message</param>
        public MessageEntry(string strReference, string strMessage, string strTitle)
        {
            this.Reference = strReference;
            this.Message = strMessage;
            this.Title = strTitle;
        }
    }

    #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