Click here to Skip to main content
11,495,743 members (64,103 online)
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 32.4K 221 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.
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
/*
 * Default.aspx Code Behind Class
 * ==============================================================
 * Creator 			Ch.V.L.Mahendra
 * Created			17-Sep-2006
 * Environments		IIS 5.*, IIS 6.0, .Net Framework 2.0
 * Description 
 * Change Log
 * ==============================================================
 * Version	Date		Author		    Changes
 * 0.1		17-Sep-2006	Ch.V.L.Mahendra	Created
 */

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Xml;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ContextSensitiveHelp.Pages.Common;
using ContextSensitiveHelp.Pages.Xml;
using ContextSensitiveHelp.Pages.UserControls;
public partial class _Default : PageManager, ICallbackEventHandler
    {       
        /// <summary>
        /// To store the result of a call back event that is returned to the client.
        /// </summary>
        private string strCallBackResult;
        protected void Page_Load(object sender, EventArgs e)
        {

            #region Local Variables

            string strContextMenuReference = string.Empty;
            string strContextMenuScript = string.Empty;
            string strHelpReference = string.Empty;
            string strHelpScript = string.Empty;

            #endregion 

            #region Call Back Event for Context Sensitive Help

            strHelpReference = Page.ClientScript.GetCallbackEventReference(this,
                                                                                  "arg",
                                                                                  "JavaScriptCallBackHelp",
                                                                                  "context"
                                                                                  );

            strHelpScript = string.Format("function CallBackHelp(arg, context) {{ {0}; }} ", strHelpReference);

            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallBackHelp", strHelpScript, true);

            #endregion

            accessBrowsedSites.DataBind();
            

        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strWhereCondition = "where";
            if (txtTitle.Text.ToString().Length > 0)
                strWhereCondition = strWhereCondition + " title = '" + txtTitle.Text  + "' ";
            else
                strWhereCondition = strWhereCondition + " title = title ";
            if (txtWebsite.Text.ToString().Length > 0)
                strWhereCondition = strWhereCondition + "AND website = '" + txtWebsite.Text  + "' ";
            else
                strWhereCondition = strWhereCondition + "AND website = website ";
            if (txtURL.Text.ToString().Length > 0)
                strWhereCondition = strWhereCondition + "AND URL = '" + txtURL.Text  + "' ";
            else
                strWhereCondition = strWhereCondition + "AND URL = URL";

            accessBrowsedSites.SelectCommand = "SELECT [title], [website], [url] FROM [BrowsedSites]" + strWhereCondition;
            accessBrowsedSites.DataBind();
        }
        protected void btnClear_Click(object sender, EventArgs e)
        {
            txtTitle.Text = string.Empty;
            txtWebsite.Text = string.Empty;
            txtURL.Text = string.Empty;
        }

        #region Method to Load the Context Sensitive Help

        /// <summary>
        /// Load context sensitive help for the corresponding screen element selected.
        /// </summary>
        /// <param name="strContext">The context to return messages for</param>
        protected string LoadContextHelp(string strContext)
        {
            try
            {
                string strTitle = string.Empty;
                string strHelp = string.Empty;
                XmlNodeList objNodeList;
                string strContextHelpKey = strContext.Replace(" ", string.Empty);
                objNodeList = XmlMessage.GetContextHelp(strContextHelpKey);
                foreach (XmlNode objNode in objNodeList)
                {
                    foreach (XmlNode objChildNode in objNode)
                    {
                        switch (objChildNode.Name)
                        {
                            case "title":
                                strTitle = Server.HtmlEncode(objChildNode.InnerText);
                                break;
                            case "message":
                                strHelp = Server.HtmlEncode(objChildNode.InnerText);
                                break;
                            default:
                                break;
                        }
                    }


                }
                if (strHelp.Equals(string.Empty))
                {
                    strTitle = strContext;
                    strHelp = "No Help Found";
                }
                strHelp = strTitle + "#" + strHelp;
                return strHelp;
            }
            catch (Exception ex)
            {
                throw;
            }


        }

        #endregion

        #region ICallbackEventHandler Members

        /// <summary>
        /// This method will return the Call back event result to the client.
        /// </summary>
        /// <returns></returns>
        public string GetCallbackResult()
        {
            return strCallBackResult;
        }
        /// <summary>
        /// This method is triggered when a call back event occurs.
        /// </summary>
        /// <param name="strEventArgument">The parameter decides the functionality for which the call
        /// back event occured and also provide the required parameter.
        /// </param>
        public void RaiseCallbackEvent(string strEventArgument)
        {
            try
            {
                char[] charSeperator = { '#' };

                //If the aruguement starts with help, it indicates that the call back event occured for 
                //providing Context Sensitive help for the selected screen element.
                if (strEventArgument.StartsWith("Help"))
                {
                    strCallBackResult = LoadContextHelp(strEventArgument.Remove(0, 4));
                }                
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }

        #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 | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 25 Sep 2006
Article Copyright 2006 by Mahi2407
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid