Introduction
This is a simple and quick help system which pops up page-specific help page on the base of URL. One can change the HTML text of the help anytime for any page by changing the XML file kept at the website folder.
Background
Recently I was asked by a client to develop a simple and quick help system which should be page specific and using which he can change the HTML text of the help anytime for any page by changing any static file kept at the website folder.
Using the Code
The default page is the dummy place from where hyperlink can be clicked to pop up the help for default page. This can be placed at some common place like master page which will bring the page id from XML on the basis of the URL on the address bar and then redirect to DynamicHelp.aspx - the page which is the common page for rendering help for any page.
lnkGetHelp.OnClientClick = "javascript:window.open('DynamicHelp.aspx?" +
GetPageQueryStringsFromXML() + "','DynamicHelp','width=500,height=300,
toolbar=no,scrollbars=yes,resizable=no,dependent=yes');return false;";
This is the page XML I am using for mapping pageid
, url
and title
, please note html
being in CDATA
, I can put any html
there:
<Page id="2" url="/Default.aspx" helptitle="Default help title">
<PageHelpText>
<![CDATA[
</PageHelpText>
</Page>
Then in the Help page, I am fetching the helptext on and title text on the basis of page id and rendering it on HTML page as follows:
XPathDocument doc = null;
XPathNavigator nav = null;
XPathExpression expr = null;
XPathNodeIterator iterator = null;
StringBuilder sbHtml = new StringBuilder();
ttlHelp.Text = (pageTitle != "0") ? pageTitle : "";
try
{
if (System.IO.File.Exists(Server.MapPath("/Components/PageHelp.xml")))
{
doc = new XPathDocument(Server.MapPath("/Components/PageHelp.xml"));
nav = doc.CreateNavigator();
expr = nav.Compile("/Pages/Page[@id=" + pageID + "]/PageHelpText");
iterator = nav.Select(expr);
if (iterator.Count > 0)
{
while (iterator.MoveNext())
{
if (iterator.Current.InnerXml != null)
{
sbHtml.Append("Help:" + pageTitle + "<br/><br/>");
sbHtml.Append(HttpUtility.HtmlDecode(iterator.Current.InnerXml));
divHelpParent.InnerHtml = sbHtml.ToString();
}
}
}
else
{
Response.Write("Sorry! No help available for this page!");
}
}
}
finally
{
sbHtml = null;
pageID = null;
pageTitle = null;
doc = null;
nav = null;
expr = null;
iterator = null;
}
Points of Interest
I liked the efficient way of bringing text from XML using XPathDocument
and the dynamic nature of this tool to add any kind of help text you want into the XML itself.
History
This is the first version, I am sure you guys can give many tips for improvement, waiting for those. Thanks!