/// <summary>
        /// The generic button "Command" event, fired by most UI buttons.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Command(object sender, CommandEventArgs e)
        {
            // Work out which button fired the event.
            switch (e.CommandName)
            {
                case "edit":
                    // Edit was clicked from Display mode, so show Edit screen.
                    showMode(DisplayMode.Edit);
                    break;
                case "close":
                    if (hdnMode.Value != "Edit")
                        // Back was clicked from New Page, or Cat Editor mode, so show Edit screen.
                        showMode(DisplayMode.Edit);
                    else
                        // Back was clicked from Edit page, so show Display screen.
                        showMode(DisplayMode.Display);
                    break;
                case "save":
                    // One of the Save buttons was clicked.
                    if (hdnMode.Value == "Edit")
                    {
                        // We're in Edit mode, check the Wiki page has a name.
                        if (String.IsNullOrEmpty(txtPageName.Text))
                        {
                            ltError.Text = "The page must have a name.";
                            pnlError.Visible = true;
                            return;
                        }

                        // Save the page data to the XML file.
                        WikiPage page = new WikiPage();
                        page.Name = ltPageName.Text;
                        page.MarkDown = txtMarkDown.Text;
                        page.Save(txtPageName.Text);

                        // Set the current page name.
                        ltPageName.Text = txtPageName.Text;

                        // Load the Display screen.
                        showMode(DisplayMode.Display);
                    }
                    else if (hdnMode.Value == "New Page")
                    {
                        // We're in New Page mode, check the Wiki page has a name, and category.
                        if (String.IsNullOrEmpty(ddlNewCategory.SelectedValue))
                        {
                            ltError.Text = "The page must belong to a category.";
                            pnlError.Visible = true;
                            return;
                        }
                        if (String.IsNullOrEmpty(txtNewPageTitle.Text))
                        {
                            ltError.Text = "The page must have a name.";
                            pnlError.Visible = true;
                            return;
                        }

                        // Save the page data to the XML file.
                        WikiPage page = new WikiPage();
                        page.Name = txtNewPageTitle.Text;
                        page.MarkDown = txtNewMarkDown.Text;
                        page.MakeNew(ddlNewCategory.SelectedValue);

                        // Set the current page name.
                        ltPageName.Text = txtNewPageTitle.Text;

                        // Clear the new page name textbox after creating a page
                        txtNewPageTitle.Text = String.Empty;

                        // Load the Display screen.
                        showMode(DisplayMode.Display);
                    }
                    break;
                case "newpage":
                    // The New Page button was clicked, so load the screen.
                    showMode(DisplayMode.New);
                    bindCategories();
                    break;
                case "cats":
                    // The Category Editor button was clicked, so load the screen.
                    showMode(DisplayMode.CategoryEditor);
                    break;
                case "link":
                    // An internal Wiki link was clicked in Display mode, so load the new Wiki page.
                    ltPageName.Text = e.CommandArgument.ToString();
                    showMode(DisplayMode.Display);
                    break;
                case "createcat":
                    if (String.IsNullOrEmpty(txtNewCatName.Text))
                    {
                        ltError.Text = "The new category must have a name.";
                        pnlError.Visible = true;
                        return;
                    }

                    var newCat = new WikiPageCategory();
                    newCat.Name = txtNewCatName.Text;
                    newCat.MakeNew();

                    // Clear the new category name textbox after creating a category
                    txtNewCatName.Text = String.Empty;

                    showMode(DisplayMode.CategoryEditor);
                    break;
                case "deletecat":
                    if (String.IsNullOrEmpty(ddlDelCatName.SelectedValue))
                    {
                        ltError.Text = "You must select a category to delete.";
                        pnlError.Visible = true;
                        return;
                    }

                    var delCat = new WikiPageCategory();
                    delCat.Name = ddlDelCatName.SelectedValue;
                    delCat.Delete();

                    showMode(DisplayMode.CategoryEditor);
                    break;
                case "savecatorder":
                    dynamic catOrder = JObject.Parse(hdnDisplayOrder.Value);

                    var reorderCat = new WikiPageCategory();
                    reorderCat.ReOrder(catOrder);

                    showMode(DisplayMode.CategoryEditor);
                    break;
                case "deletepage":
                    var delPage = new WikiPage();
                    delPage.Name = hdnPageName.Value;
                    delPage.Delete();

                    // The page we were working on has gone, so reset to the default.
                    ltPageName.Text = String.Empty;

                    showMode(DisplayMode.Display);
                    break;
            }
        }
        private String loadRaw(String pageName)
        {
            WikiPage page = new WikiPage();
            if (page.GetPage(pageName))
                ltPageName.Text = page.Name;

            return page.MarkDown;
        }