Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » Ajax » General » Downloads
 
Add your own
alternative version

Context Sensitive Help using Client Callbacks - AJAX Style

, 25 Sep 2006
This article is all about providing Context Sensitive Help in a web page, asynchronously or AJAX style, using Client Callbacks in .NET 2.0.
contextsensitivehelp_src.zip
ContextSensitiveHelpCode
ContextSensitiveHelp_src
ContextSensitiveHelp
App_Code
App_Themes
ControlsTheme
ContextSensitiveHelp.skin
CSS
Database
SampleDataBase.mdb
IMG
ContextSensitiveHelp.gif
Scripts
UserControls
Xml
Messages.dtd
/*
 * 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

Share

About the Author

Mahi2407
Web Developer
India India
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 25 Sep 2006
Article Copyright 2006 by Mahi2407
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid