/// <summary>
        /// Handles a delete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cmdDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Null.IsNull(itemId))
                {
                    var controller = new ExpandableTextHtmlController();
                    controller.DeleteExpandableTextHtml(ModuleId, itemId);

                    //Purge the cache
                    ModuleController.SynchronizeModule(ModuleId);

                    //Call cancel to return
                    cmdCancel_Click(sender, e);
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        /// <summary>
        /// This method handles an insert or update!
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                var controller = new ExpandableTextHtmlController();
                var item = new ExpandableTextHtmlInfo();

                txtTitle.HtmlEncode = false;
                item.Title = txtTitle.Text;
                txtBody.HtmlEncode = false;
                item.Body = txtBody.Text;

                item.LastUpdated = DateTime.Now;
                item.ModuleId = ModuleId;
                item.ItemId = itemId;
                item.IsExpanded = chkIsExpanded.Checked;
                item.SortOrder = int.Parse(txtSortOrder.Text);
                item.RequiredRole = ddlRequiredRole.SelectedValue;

                //Do we need to default the publish date
                item.PublishDate = string.IsNullOrEmpty(txtPublishDate.Text) ? DateTime.Now.Date : DateTime.Parse(txtPublishDate.Text);

                //Determine if we need to clean the title text
                if (item.Title.StartsWith("<p>") && item.Title.EndsWith("</p>"))
                {
                    item.Title = item.Title.Substring(3, item.Title.Length - 7);
                }

                //determine if we are adding or updating
                if (Null.IsNull(item.ItemId))
                    controller.AddExpandableTextHtml(item);
                else
                    controller.UpdateExpandableTextHtml(item);

                //Purge the cache
                ModuleController.SynchronizeModule(ModuleId);

                //Call cancel to return
                cmdCancel_Click(sender, e);
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                jQuery.RequestDnnPluginsRegistration();

                //Store the item id on every load
                if (Request.QueryString["EntryId"] != null)
                {
                    itemId = Int32.Parse(Request.QueryString["EntryId"]);
                }

                if (!IsPostBack)
                {
                    //Load the list of roles
                    var roleController = new RoleController();
                    ddlRequiredRole.DataSource = roleController.GetPortalRoles(PortalId);
                    ddlRequiredRole.DataTextField = "RoleName";
                    ddlRequiredRole.DataValueField = "RoleName";
                    ddlRequiredRole.DataBind();
                    ddlRequiredRole.Items.Insert(0,
                                                 new ListItem(
                                                     Localization.GetString("SameAsModule", LocalResourceFile),
                                                     "-1"));

                    //check we have an item to lookup
                    if (!Null.IsNull(itemId))
                    {
                        //load the item
                        var controller = new ExpandableTextHtmlController();
                        var item = controller.GetExpandableTextHtml(ModuleId, itemId);

                        //ensure we have an item
                        if (item != null)
                        {
                            txtTitle.Text = item.Title;
                            txtBody.Text = item.Body;
                            chkIsExpanded.Checked = item.IsExpanded;
                            txtSortOrder.Text = item.SortOrder.ToString();
                            litContentId.Text = string.Format("ICG_ETH_{0}", item.ItemId.ToString());
                            txtPublishDate.Text = item.PublishDate.ToShortDateString();
                            var foundItem = ddlRequiredRole.Items.FindByValue(item.RequiredRole);
                            if (foundItem != null)
                                ddlRequiredRole.SelectedValue = item.RequiredRole;
                        }
                        else
                            Response.Redirect(Globals.NavigateURL(), true);
                    }
                    else
                    {
                        cmdDelete.Visible = false;

                        //Default sort order to 0
                        txtSortOrder.Text = "0";
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        /// <summary>
        /// This method will bind the text elements to the control
        /// </summary>
        /// <param name="sortOrder"></param>
        private void BindTextListing(object sortOrder)
        {
            var controller = new ExpandableTextHtmlController();
            var items = controller.GetExpandableTextHtmls(ModuleId, sortOrder.ToString());

            //If not editable, filter the list
            if (!IsEditable)
            {
                //Only show currently published items, as well as items that are either visible to all, OR to this users role
                items = items.Where(
                    x => x.PublishDate < DateTime.Now
                         && (x.RequiredRole.Equals("-1")
                             || UserInfo.IsInRole(x.RequiredRole))).ToList();
            }

            //See if we have items
            if (items != null && items.Count > 0)
            {
                //Check to see if limiting display, or see if we have less items than the limit
                if (_displayLimit == -1 || items.Count <= _displayLimit)
                {
                    //Bind list directly
                    rptListing.DataSource = items;
                    rptListing.DataBind();
                }
                else
                {
                    //Bind via Paged Data Source
                    var oDs = new PagedDataSource();
                    oDs.DataSource = items;
                    oDs.AllowPaging = true;
                    oDs.PageSize = _displayLimit;
                    rptListing.DataSource = oDs;
                    rptListing.DataBind();

                    //SHow all
                    pShowAll.Visible = true;
                    hlShowAll.Text = _showAllText;
                    hlShowAll.NavigateUrl = Globals.NavigateURL(TabId) + "?show=all";
                }
            }
            else
            {
                //Configured but no content, hide list
                HideDisplayAndDisplayNoContent();
            }
        }