private void CmdUpdateClick(object sender, EventArgs e)
        {
            try
            {
                var av = (Article)VersionInfoObject;

                txtMessage.Text = string.Empty;
                bool error = false;

                //Removed the check for the Item Description length as we no longer have a restriction on this

                //if (TextBoxMaxLengthExceeded(this.itemEditControl.DescriptionText, "Article Description", 4000))
                //{
                //    error = true;
                //}

                if (TextBoxMaxLengthExceeded(txtVersionDescription.Text, "Version Description", 8000))
                {
                    error = true;
                }

                if (!parentCategoryRelationship.IsValid)
                {
                    error            = true;
                    txtMessage.Text += Localization.GetString("ErrorSelectCategory.Text", LocalResourceFile);
                }

                if (!itemApprovalStatus.IsValid && itemApprovalStatus.Visible)
                {
                    error            = true;
                    txtMessage.Text += Localization.GetString("ErrorApprovalStatus.Text", LocalResourceFile);
                }

                if (!itemEditControl.IsValid)
                {
                    error            = true;
                    txtMessage.Text += itemEditControl.ErrorMessage;
                }

                if (Convert.ToInt32(ddlDisplayTabId.SelectedValue, CultureInfo.InvariantCulture) > -1)
                {
                    VersionInfoObject.DisplayTabId = Convert.ToInt32(ddlDisplayTabId.SelectedValue, CultureInfo.InvariantCulture);
                }
                else
                {
                    error            = true;
                    txtMessage.Text += Localization.GetString("ErrorDisplayPage.Text", LocalResourceFile);
                }

                if (error)
                {
                    txtMessage.Visible = true;
                    return;
                }

                av.ArticleText        = TeArticleText.Text;
                av.VersionDescription = txtVersionDescription.Text;
                av.VersionNumber      = txtVersionNumber.Text;
                av.Description        = itemEditControl.DescriptionText;
                //we need to look at making moduleid be configurable at anytime, not just on item creation, this makes previewing items impossible
                //if (av.IsNew)
                int newModuleId = Utility.GetModuleIdFromDisplayTabId(VersionInfoObject.DisplayTabId, PortalId, Utility.DnnFriendlyModuleName);
                if (newModuleId > 0)
                {
                    VersionInfoObject.ModuleId = newModuleId;
                }
                else
                {
                    newModuleId = Utility.GetModuleIdFromDisplayTabId(VersionInfoObject.DisplayTabId, PortalId, Utility.DnnFriendlyModuleNameTextHTML);
                    if (newModuleId > 0)
                    {
                        VersionInfoObject.ModuleId = newModuleId;
                    }
                }

                //create a relationship
                var irel = new ItemRelationship {
                    RelationshipTypeId = Util.RelationshipType.ItemToParentCategory.GetId()
                };
                int[] ids = parentCategoryRelationship.GetSelectedItemIds();

                //check for parent category, if none then add a relationship for Top Level Item
                if (ids.Length > 0)
                {
                    irel.ParentItemId = ids[0];
                    VersionInfoObject.Relationships.Add(irel);
                }

                foreach (int i in relatedCategoryRelationships.GetSelectedItemIds())
                {
                    var irco = new ItemRelationship
                    {
                        RelationshipTypeId = Util.RelationshipType.ItemToRelatedCategory.GetId(),
                        ParentItemId       = i
                    };
                    av.Relationships.Add(irco);
                }

                if (AllowTags)
                {
                    av.Tags.Clear();
                    //Add the tags to the ItemTagCollection
                    foreach (Tag t in Tag.ParseTags(tagEntryControl.TagList, PortalId))
                    {
                        ItemTag it = ItemTag.Create();
                        it.TagId = Convert.ToInt32(t.TagId, CultureInfo.InvariantCulture);
                        av.Tags.Add(it);
                    }
                }


                if (av.Description == string.Empty)
                {
                    //trim article text to populate description

                    if (!Utility.HasValue(av.Description) || !Utility.HasValue(av.MetaDescription))
                    {
                        string description = DotNetNuke.Common.Utilities.HtmlUtils.StripTags(av.ArticleText, false);
                        if (!Utility.HasValue(av.Description))
                        {
                            av.Description = Utility.TrimDescription(3997, description) + "...";// description + "...";
                        }
                    }
                }

                //auto populate the meta description if it's not populated already
                if (!Utility.HasValue(av.MetaDescription))
                {
                    string description = DotNetNuke.Common.Utilities.HtmlUtils.StripTags(av.Description, false);
                    av.MetaDescription = Utility.TrimDescription(399, description);
                }

                //Save the ItemVersionSettings
                SaveSettings();

                //approval status
                av.ApprovalStatusId = chkUseApprovals.Checked && UseApprovals ? itemApprovalStatus.ApprovalStatusId : ApprovalStatus.Approved.GetId();

                VersionInfoObject.Save(UserId);

                string returnUrl = Server.UrlDecode(Request.QueryString["returnUrl"]);
                if (!Utility.HasValue(returnUrl))
                {
                    Response.Redirect(Globals.NavigateURL(TabId, "", "", "ctl=" + Utility.AdminContainer, "mid=" + ModuleId.ToString(CultureInfo.InvariantCulture),
                                                          "adminType=itemCreated", "itemId=" + VersionInfoObject.ItemId.ToString(CultureInfo.InvariantCulture)), true);
                }
                else
                {
                    Response.Redirect(returnUrl);
                }
            }

            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        private void CmdUpdateClick(object sender, EventArgs e)
        {
            try
            {
                txtMessage.Text = string.Empty;
                bool error = false;

                //create a relationship
                var irel = new ItemRelationship {
                    RelationshipTypeId = Util.RelationshipType.ItemToParentCategory.GetId()
                };
                int[] ids = parentCategoryRelationships.GetSelectedItemIds();

                //check for parent category, if none then add a relationship for Top Level Item
                if (ids.Length == 0)
                {
                    //add relationship to TLC
                    irel.RelationshipTypeId = Util.RelationshipType.CategoryToTopLevelCategory.GetId();
                    irel.ParentItemId       = TopLevelCategoryItemType.Category.GetId();
                    VersionInfoObject.Relationships.Add(irel);
                }
                else
                {
                    irel.ParentItemId = ids[0];
                    VersionInfoObject.Relationships.Add(irel);
                }

                //check for parent category, if none then add a relationship for Top Level Item
                //foreach (int i in this.irRelated.GetSelectedItemIds())
                //{
                //    ItemRelationship irco = ItemRelationship.Create();
                //    irco.RelationshipTypeId = Util.RelationshipType.ItemToRelatedCategory.GetId();
                //    irco.ParentItemId = i;
                //    VersionInfoObject.Relationships.Add(irco);
                //}

                if (itemEditControl.IsValid == false)
                {
                    error            = true;
                    txtMessage.Text += itemEditControl.ErrorMessage;
                }

                if (Convert.ToInt32(ddlDisplayTabId.SelectedValue, CultureInfo.InvariantCulture) < -1)
                {
                    error = true;

                    txtMessage.Text += Localization.GetString("ChooseAPage", LocalResourceFile);
                }

                if (Convert.ToInt32(ddlChildDisplayTabId.SelectedValue, CultureInfo.InvariantCulture) == -1)
                {
                    error            = true;
                    txtMessage.Text += Localization.GetString("ChooseChildPage", LocalResourceFile);
                }

                if (!itemApprovalStatus.IsValid)
                {
                    txtMessage.Text += Localization.GetString("ChooseApprovalStatus", LocalResourceFile);
                }

                if (error)
                {
                    txtMessage.Visible = true;
                    return;
                }
                VersionInfoObject.Description = itemEditControl.DescriptionText;


                //auto populate the meta description if it's not populated already
                if (!Utility.HasValue(VersionInfoObject.MetaDescription))
                {
                    string description = DotNetNuke.Common.Utilities.HtmlUtils.StripTags(VersionInfoObject.Description, false);
                    VersionInfoObject.MetaDescription = Utility.TrimDescription(399, description);
                }


                if (VersionInfoObject.IsNew)
                {
                    VersionInfoObject.ModuleId = ModuleId;
                }

                int sortCount = 0;

                foreach (int i in featuredArticlesRelationships.GetSelectedItemIds())
                {
                    var irArticleso = new ItemRelationship
                    {
                        RelationshipTypeId = Util.RelationshipType.ItemToFeaturedItem.GetId(),
                        ParentItemId       = i
                    };

                    if (Utility.HasValue(featuredArticlesRelationships.GetAdditionalSetting("startDate", i.ToString(CultureInfo.InvariantCulture))))
                    {
                        irArticleso.StartDate = featuredArticlesRelationships.GetAdditionalSetting("startDate", i.ToString(CultureInfo.InvariantCulture));
                    }
                    if (Utility.HasValue(featuredArticlesRelationships.GetAdditionalSetting("endDate", i.ToString(CultureInfo.InvariantCulture))))
                    {
                        irArticleso.EndDate = featuredArticlesRelationships.GetAdditionalSetting("endDate", i.ToString(CultureInfo.InvariantCulture));
                    }
                    irArticleso.SortOrder = sortCount;

                    sortCount++;
                    VersionInfoObject.Relationships.Add(irArticleso);
                }

                SaveSettings();

                //approval status
                if (chkUseApprovals.Checked && UseApprovals)
                {
                    VersionInfoObject.ApprovalStatusId = itemApprovalStatus.ApprovalStatusId;
                }
                else
                {
                    VersionInfoObject.ApprovalStatusId = ApprovalStatus.Approved.GetId();
                }

                VersionInfoObject.Save(UserId);

                if (SecurityFilter.IsSecurityEnabled(PortalId))
                {
                    categoryPermissions.CategoryId = VersionInfoObject.ItemId;
                    categoryPermissions.Save();
                }

                if (chkResetChildDisplayTabs.Checked)
                {
                    ((Category)VersionInfoObject).CascadeChildDisplayTab(UserId);
                }

                string returnUrl = Server.UrlDecode(Request.QueryString["returnUrl"]);
                if (!Utility.HasValue(returnUrl))
                {
                    Response.Redirect(Globals.NavigateURL(TabId, "", "", "ctl=" + Utility.AdminContainer, "mid=" + ModuleId, "adminType=itemCreated",
                                                          "itemId=" + VersionInfoObject.ItemId), true);
                }
                else
                {
                    Response.Redirect(returnUrl);
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }