Ejemplo n.º 1
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string errorMessage = new Validator()
                              .NotEmpty(txtControlDisplayName.Text.Trim(), rfvDisplayName.ErrorMessage)
                              .NotEmpty(txtControlName.Text.Trim(), rfvName.ErrorMessage)
                              .IsCodeName(txtControlName.Text.Trim(), GetString("general.errorcodenameinidentificatorformat"))
                              .Result;

        if ((string.IsNullOrEmpty(errorMessage)) && (!FileSystemSelector.IsValid()))
        {
            errorMessage = FileSystemSelector.ValidationError;
        }

        if (string.IsNullOrEmpty(errorMessage))
        {
            // Get object
            InlineControlInfo inlineControlObj = InlineControlInfoProvider.GetInlineControlInfo(controlId);
            EditedObject = inlineControlObj;

            // Update properties
            inlineControlObj.ControlDescription   = txtControlDescription.Text.Trim();
            inlineControlObj.ControlDisplayName   = txtControlDisplayName.Text.Trim();
            inlineControlObj.ControlParameterName = txtControlParameterName.Text.Trim();
            inlineControlObj.ControlName          = txtControlName.Text.Trim();
            inlineControlObj.ControlFileName      = FileSystemSelector.Value.ToString().Trim();
            inlineControlObj.ControlResourceID    = ValidationHelper.GetInteger(drpModule.Value, 0);

            try
            {
                // Save changes
                InlineControlInfoProvider.SetInlineControlInfo(inlineControlObj);
                ShowInformation(GetString("general.changessaved"));

                // Refresh header with display name
                ScriptHelper.RefreshTabHeader(Page, null);
            }
            catch (Exception ex)
            {
                ShowError(ex.Message.Replace("%%name%%", txtControlName.Text));
            }
        }
        else
        {
            ShowError(errorMessage);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Validate inputs
        string errorMessage = new Validator().NotEmpty(txtControlDisplayName.Text.Trim(), rfvDisplayName.ErrorMessage)
                              .NotEmpty(txtControlName.Text.Trim(), rfvName.ErrorMessage)
                              .IsCodeName(txtControlName.Text.Trim(), GetString("general.errorcodenameinidentifierformat")).Result;

        if ((string.IsNullOrEmpty(errorMessage)) && (!FileSystemSelector.IsValid()))
        {
            errorMessage = FileSystemSelector.ValidationError;
        }

        if (string.IsNullOrEmpty(errorMessage))
        {
            // Create new inline control object
            InlineControlInfo inlineControlObj = new InlineControlInfo();

            inlineControlObj.ControlDescription   = txtControlDescription.Text.Trim();
            inlineControlObj.ControlDisplayName   = txtControlDisplayName.Text.Trim();
            inlineControlObj.ControlFileName      = FileSystemSelector.Value.ToString().Trim();
            inlineControlObj.ControlParameterName = txtControlParameterName.Text.Trim();
            inlineControlObj.ControlName          = txtControlName.Text.Trim();

            try
            {
                // Create new inline control
                InlineControlInfoProvider.SetInlineControlInfo(inlineControlObj);
                if ((chkAssign.Visible) && (chkAssign.Checked) && (CMSContext.CurrentSite != null))
                {
                    // Add new control to the actual site
                    InlineControlSiteInfoProvider.AddInlineControlToSite(inlineControlObj.ControlID, CMSContext.CurrentSiteID);
                }
                // Redirect to edit page
                URLHelper.Redirect("Frameset.aspx?inlinecontrolid=" + Convert.ToString(inlineControlObj.ControlID) + "&saved=1");
            }
            catch (Exception ex)
            {
                ShowError(ex.Message.Replace("%%name%%", txtControlName.Text));
            }
        }
        else
        {
            ShowError(errorMessage);
        }
    }
    /// <summary>
    /// Updates existing or creates new web part.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Validate the text box fields
        string errorMessage = new Validator().IsCodeName(txtWebPartName.Text, GetString("general.invalidcodename")).Result;

        if (errorMessage != String.Empty)
        {
            ShowError(errorMessage);
            return;
        }

        WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webPartId);

        if (wi != null)
        {
            string webpartPath = GetWebPartPhysicalPath(FileSystemSelector.Value.ToString());

            txtWebPartName.Text        = TextHelper.LimitLength(txtWebPartName.Text.Trim(), 100, "");
            txtWebPartDisplayName.Text = TextHelper.LimitLength(txtWebPartDisplayName.Text.Trim(), 100, "");

            // Perform validation
            errorMessage = new Validator().NotEmpty(txtWebPartName.Text, rfvWebPartName.ErrorMessage).IsCodeName(txtWebPartName.Text, GetString("general.invalidcodename"))
                           .NotEmpty(txtWebPartDisplayName.Text, rfvWebPartDisplayName.ErrorMessage).Result;

            // Check file name
            if (wi.WebPartParentID <= 0)
            {
                if (!FileSystemSelector.IsValid())
                {
                    errorMessage += FileSystemSelector.ValidationError;
                }
            }

            if (errorMessage != String.Empty)
            {
                ShowError(errorMessage);
                return;
            }


            string oldDisplayName = wi.WebPartDisplayName;
            string oldCodeName    = wi.WebPartName;
            int    oldCategory    = wi.WebPartCategoryID;

            // Remove starting CMSwebparts folder
            string filename = FileSystemSelector.Value.ToString().Trim();
            if (filename.ToLowerCSafe().StartsWithCSafe("~/cmswebparts/"))
            {
                filename = filename.Substring("~/cmswebparts/".Length);
            }


            // If name changed, check if new name is unique
            if (CMSString.Compare(wi.WebPartName, txtWebPartName.Text, true) != 0)
            {
                WebPartInfo webpart = WebPartInfoProvider.GetWebPartInfo(txtWebPartName.Text);
                if (webpart != null)
                {
                    ShowError(GetString("Development.WebParts.WebPartNameAlreadyExist").Replace("%%name%%", txtWebPartName.Text));
                    return;
                }
            }

            wi.WebPartName                 = txtWebPartName.Text;
            wi.WebPartDisplayName          = txtWebPartDisplayName.Text;
            wi.WebPartDescription          = txtWebPartDescription.Text.Trim();
            wi.WebPartFileName             = filename;
            wi.WebPartType                 = ValidationHelper.GetInteger(drpWebPartType.SelectedValue, 0);
            wi.WebPartSkipInsertProperties = chkSkipInsertProperties.Checked;

            wi.WebPartLoadGeneration = drpGeneration.Value;
            wi.WebPartResourceID     = ValidationHelper.GetInteger(drpModule.Value, 0);

            FileSystemSelector.Value = wi.WebPartFileName;

            wi.WebPartCategoryID = ValidationHelper.GetInteger(categorySelector.Value, 0);

            WebPartInfoProvider.SetWebPartInfo(wi);

            // if DisplayName or Category was changed, then refresh web part tree and header
            if ((oldCodeName != wi.WebPartName) || (oldDisplayName != wi.WebPartDisplayName) || (oldCategory != wi.WebPartCategoryID))
            {
                ltlScript.Text += ScriptHelper.GetScript(
                    "parent.parent.frames['webparttree'].location.replace('WebPart_Tree.aspx?webpartid=" + wi.WebPartID + "'); \n" +
                    "parent.frames['webparteditheader'].location.replace(parent.frames['webparteditheader'].location.href); \n"
                    );
            }

            ShowChangesSaved();
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Creates new web part.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Validate the text box fields
        string errorMessage = new Validator().IsCodeName(txtWebPartName.Text, GetString("general.invalidcodename")).Result;

        // Validate and trim file name textbox only if it's visible
        if (radNewWebPart.Checked && radNewFile.Checked)
        {
            if (String.IsNullOrEmpty(errorMessage))
            {
                errorMessage = new Validator().IsFileName(Path.GetFileName(txtCodeFileName.Text), GetString("WebPart_Clone.InvalidFileName")).Result;
            }
        }

        // Check file name
        if (radExistingFile.Checked && radNewWebPart.Checked)
        {
            if (String.IsNullOrEmpty(errorMessage))
            {
                string webpartPath = WebPartInfoProvider.GetWebPartPhysicalPath(FileSystemSelector.Value.ToString());
                errorMessage = new Validator().IsFileName(Path.GetFileName(webpartPath), GetString("WebPart_Clone.InvalidFileName")).Result;
            }
        }

        if (!String.IsNullOrEmpty(errorMessage))
        {
            ShowError(HTMLHelper.HTMLEncode(errorMessage));
            return;
        }

        // Run in transaction
        using (var tr = new CMSTransactionScope())
        {
            WebPartInfo wi = new WebPartInfo();

            // Check if new name is unique
            WebPartInfo webpart = WebPartInfoProvider.GetWebPartInfo(txtWebPartName.Text);
            if (webpart != null)
            {
                ShowError(GetString("Development.WebParts.WebPartNameAlreadyExist").Replace("%%name%%", txtWebPartName.Text));
                return;
            }

            string filename = String.Empty;

            if (radNewWebPart.Checked)
            {
                if (radExistingFile.Checked)
                {
                    filename = FileSystemSelector.Value.ToString().Trim();

                    if (filename.ToLowerCSafe().StartsWithCSafe("~/cmswebparts/"))
                    {
                        filename = filename.Substring("~/cmswebparts/".Length);
                    }
                }
                else
                {
                    filename = txtCodeFileName.Text.Trim();

                    if (!filename.EndsWithCSafe(".ascx"))
                    {
                        filename += ".ascx";
                    }
                }
            }

            wi.WebPartDisplayName   = txtWebPartDisplayName.Text.Trim();
            wi.WebPartFileName      = filename;
            wi.WebPartName          = txtWebPartName.Text.Trim();
            wi.WebPartCategoryID    = QueryHelper.GetInteger("parentobjectid", 0);
            wi.WebPartDescription   = "";
            wi.WebPartDefaultValues = "<form></form>";
            // Initialize WebPartType - fill it with the default value
            wi.WebPartType = wi.WebPartType;

            // Inherited web part
            if (radInherited.Checked)
            {
                // Check if is selected webpart and isn't category item
                if (ValidationHelper.GetInteger(webpartSelector.Value, 0) <= 0)
                {
                    ShowError(GetString("WebPartNew.InheritedCategory"));
                    return;
                }

                int parentId = ValidationHelper.GetInteger(webpartSelector.Value, 0);
                var parent   = WebPartInfoProvider.GetWebPartInfo(parentId);
                if (parent != null)
                {
                    wi.WebPartType                 = parent.WebPartType;
                    wi.WebPartResourceID           = parent.WebPartResourceID;
                    wi.WebPartSkipInsertProperties = parent.WebPartSkipInsertProperties;
                }

                wi.WebPartParentID = parentId;

                // Create empty default values definition
                wi.WebPartProperties = "<defaultvalues></defaultvalues>";
            }
            else
            {
                // Check if filename was added
                if (FileSystemSelector.Visible && !FileSystemSelector.IsValid())
                {
                    ShowError(FileSystemSelector.ValidationError);
                    return;
                }

                wi.WebPartProperties = "<form></form>";
                wi.WebPartParentID   = 0;
            }

            // Save the web part
            WebPartInfoProvider.SetWebPartInfo(wi);

            if (radNewFile.Checked && radNewWebPart.Checked)
            {
                string physicalFile = WebPartInfoProvider.GetFullPhysicalPath(wi);
                if (!File.Exists(physicalFile))
                {
                    string ascx;
                    string code;
                    string designer;

                    // Write the files
                    try
                    {
                        WebPartInfoProvider.GenerateWebPartCode(wi, null, out ascx, out code, out designer);

                        string folder = Path.GetDirectoryName(physicalFile);

                        // Ensure the folder
                        if (!Directory.Exists(folder))
                        {
                            Directory.CreateDirectory(folder);
                        }

                        File.WriteAllText(physicalFile, ascx);
                        File.WriteAllText(physicalFile + ".cs", code);

                        // Designer file
                        if (!String.IsNullOrEmpty(designer))
                        {
                            File.WriteAllText(physicalFile + ".designer.cs", designer);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogAndShowError("WebParts", "GENERATEFILES", ex, true);
                        return;
                    }
                }
                else
                {
                    ShowError(String.Format(GetString("General.FileExistsPath"), physicalFile));
                    return;
                }
            }

            // Refresh web part tree
            ScriptHelper.RegisterStartupScript(this, typeof(string), "reloadframee", ScriptHelper.GetScript(
                                                   "parent.location = '" + UIContextHelper.GetElementUrl("cms.design", "Development.Webparts", false, wi.WebPartID) + "';"));

            PageBreadcrumbs.Items[1].Text = HTMLHelper.HTMLEncode(wi.WebPartDisplayName);
            ShowChangesSaved();
            plcTable.Visible = false;

            tr.Commit();
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Creates new web part.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Validate the text box fields
        string errorMessage = new Validator().IsCodeName(txtWebPartName.Text, GetString("general.invalidcodename")).Result;

        // Check file name
        if (errorMessage == String.Empty)
        {
            string webpartPath = GetWebPartPhysicalPath(FileSystemSelector.Value.ToString());

            if (!radInherited.Checked)
            {
                errorMessage = new Validator().IsFileName(Path.GetFileName(webpartPath), GetString("WebPart_Clone.InvalidFileName")).Result;
            }
        }

        if (errorMessage != String.Empty)
        {
            lblError.Text    = HTMLHelper.HTMLEncode(errorMessage);
            lblError.Visible = true;
            return;
        }

        WebPartInfo wi = new WebPartInfo();

        // Check if new name is unique
        WebPartInfo webpart = WebPartInfoProvider.GetWebPartInfo(txtWebPartName.Text);

        if (webpart != null)
        {
            lblError.Visible = true;
            lblError.Text    = GetString("Development.WebParts.WebPartNameAlreadyExist").Replace("%%name%%", txtWebPartName.Text);
            return;
        }


        string filename = FileSystemSelector.Value.ToString().Trim();

        if (filename.ToLower().StartsWith("~/cmswebparts/"))
        {
            filename = filename.Substring("~/cmswebparts/".Length);
        }

        wi.WebPartDisplayName   = txtWebPartDisplayName.Text.Trim();
        wi.WebPartFileName      = filename;
        wi.WebPartName          = txtWebPartName.Text.Trim();
        wi.WebPartCategoryID    = QueryHelper.GetInteger("parentid", 0);
        wi.WebPartDescription   = "";
        wi.WebPartDefaultValues = "<form></form>";

        // Inherited webpart
        if (radInherited.Checked)
        {
            // Check if is selected webpart and isn't category item
            if (ValidationHelper.GetInteger(webpartSelector.Value, 0) <= 0)
            {
                lblError.Visible = true;
                lblError.Text    = GetString("WebPartNew.InheritedCategory");
                return;
            }

            wi.WebPartParentID = ValidationHelper.GetInteger(webpartSelector.Value, 0);

            // Create empty default values definition
            wi.WebPartProperties = "<defaultvalues></defaultvalues>";
        }
        else
        {
            // Check if filename was added
            if (!FileSystemSelector.IsValid())
            {
                lblError.Visible = true;
                lblError.Text    = FileSystemSelector.ValidationError;

                return;
            }
            else
            {
                wi.WebPartProperties = "<form></form>";
                wi.WebPartParentID   = 0;
            }
        }


        WebPartInfoProvider.SetWebPartInfo(wi);

        // Refresh web part tree
        ScriptHelper.RegisterStartupScript(this, typeof(string), "reloadframe", ScriptHelper.GetScript(
                                               "parent.frames['webparttree'].location.replace('" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Tree.aspx") + "?webpartid=" + wi.WebPartID + "');" +
                                               "location.replace('" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Edit_Frameset.aspx") + "?webpartid=" + wi.WebPartID + "')"
                                               ));

        pageTitleTabs[1, 0] = HTMLHelper.HTMLEncode(wi.WebPartDisplayName);
        this.CurrentMaster.Title.Breadcrumbs = pageTitleTabs;
        lblInfo.Visible  = true;
        lblInfo.Text     = GetString("General.ChangesSaved");
        plcTable.Visible = false;
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Save button action.
    /// </summary>
    protected void HeaderActions_ActionPerformed(object sender, CommandEventArgs e)
    {
        switch (e.CommandName.ToLower())
        {
        case "lnksave_click":
            // Template has to exist
            if (pti == null)
            {
                return;
            }

            // Limit text length
            txtTemplateCodeName.Text    = TextHelper.LimitLength(txtTemplateCodeName.Text.Trim(), 100, "");
            txtTemplateDisplayName.Text = TextHelper.LimitLength(txtTemplateDisplayName.Text.Trim(), 200, "");

            // Finds whether required fields are not empty
            string result = String.Empty;

            result = new Validator().NotEmpty(txtTemplateDisplayName.Text, GetString("Administration-PageTemplate_General.ErrorEmptyTemplateDisplayName")).NotEmpty(txtTemplateCodeName.Text, GetString("Administration-PageTemplate_General.ErrorEmptyTemplateCodeName"))
                     .IsCodeName(txtTemplateCodeName.Text, GetString("general.invalidcodename"))
                     .Result;

            if ((result == String.Empty) && (SelectedPageType == PageTemplateTypeEnum.Aspx || SelectedPageType == PageTemplateTypeEnum.AspxPortal))
            {
                if (!FileSystemSelector.IsValid())
                {
                    result = FileSystemSelector.ValidationError;
                }
            }

            // If name changed, check if new name is unique
            if ((result == String.Empty) && (String.Compare(pti.CodeName, txtTemplateCodeName.Text, true) != 0))
            {
                if (PageTemplateInfoProvider.PageTemplateNameExists(txtTemplateCodeName.Text))
                {
                    result = GetString("general.codenameexists");
                }
            }

            if (result == "")
            {
                // Update page template info
                pti.DisplayName = txtTemplateDisplayName.Text;
                pti.CodeName    = txtTemplateCodeName.Text;
                pti.Description = txtTemplateDescription.Text;
                pti.CategoryID  = Convert.ToInt32(categorySelector.Value);

                if (SelectedPageType == PageTemplateTypeEnum.Portal)
                {
                    pti.IsPortal = true;
                    pti.FileName = String.Empty;

                    // Save inherit levels
                    if (!chkShowAsMasterTemplate.Checked)
                    {
                        pti.InheritPageLevels = ValidationHelper.GetString(lvlElem.Value, "");
                    }
                    else
                    {
                        pti.InheritPageLevels = "/";
                    }

                    // Show hide inherit levels radio buttons
                    pti.ShowAsMasterTemplate = chkShowAsMasterTemplate.Checked;
                }
                else
                {
                    // ASPX page templates
                    pti.IsPortal             = false;
                    pti.FileName             = FileSystemSelector.Value.ToString();
                    pti.ShowAsMasterTemplate = false;
                    pti.InheritPageLevels    = "";
                }

                pti.PageTemplateType = SelectedPageType;

                pti.IsReusable = pageTemplateIsReusable;
                pti.WebParts   = pageTemplateWebParts;

                try
                {
                    // Save the template and update the header
                    PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                    ScriptHelper.RegisterStartupScript(this, typeof(string), "pageTemplateSaveScript", ScriptHelper.GetScript("RefreshContent()"));
                    lblInfo.Text = ResHelper.GetString("General.ChangesSaved");
                }
                catch (Exception ex)
                {
                    lblError.Text    = ex.Message;
                    lblError.Visible = true;
                }
            }
            else
            {
                rfvTemplateDisplayName.Visible = false;
                rfvTemplateCodeName.Visible    = false;

                lblError.Visible = true;
                lblError.Text    = result;
            }
            break;
        }
    }
Ejemplo n.º 7
0
 /// <summary>
 /// Validates the return value of form control.
 /// </summary>
 public override bool IsValid()
 {
     return(FileSystemSelector.IsValid());
 }
    /// <summary>
    /// Save button action.
    /// </summary>
    protected void ObjectManager_OnSaveData(object sender, SimpleObjectManagerEventArgs e)
    {
        // Template has to exist
        if (PageTemplate == null)
        {
            return;
        }

        // Limit text length
        txtTemplateCodeName.Text    = TextHelper.LimitLength(txtTemplateCodeName.Text.Trim(), 100, "");
        txtTemplateDisplayName.Text = TextHelper.LimitLength(txtTemplateDisplayName.Text.Trim(), 200, "");

        // Finds whether required fields are not empty
        string result = String.Empty;

        result = new Validator().NotEmpty(txtTemplateDisplayName.Text, GetString("Administration-PageTemplate_General.ErrorEmptyTemplateDisplayName")).NotEmpty(txtTemplateCodeName.Text, GetString("Administration-PageTemplate_General.ErrorEmptyTemplateCodeName"))
                 .IsCodeName(txtTemplateCodeName.Text, GetString("general.invalidcodename"))
                 .Result;

        if ((result == String.Empty) && (SelectedPageType == PageTemplateTypeEnum.Aspx || SelectedPageType == PageTemplateTypeEnum.AspxPortal))
        {
            if (!FileSystemSelector.IsValid())
            {
                result = FileSystemSelector.ValidationError;
            }
        }

        // If name changed, check if new name is unique
        if ((result == String.Empty) && (CMSString.Compare(PageTemplate.CodeName, txtTemplateCodeName.Text, true) != 0))
        {
            if (PageTemplateInfoProvider.PageTemplateNameExists(txtTemplateCodeName.Text))
            {
                result = GetString("general.codenameexists");
            }
        }


        // Check dashboard prerequisites
        if ((PageTemplate.PageTemplateId > 0) && (SelectedPageType == PageTemplateTypeEnum.Dashboard))
        {
            // Check live site usage
            TreeProvider            tp         = new TreeProvider(CMSContext.CurrentUser);
            NodeSelectionParameters parameters = new NodeSelectionParameters()
            {
                ClassNames = TreeProvider.ALL_CLASSNAMES,
                SiteName   = TreeProvider.ALL_SITES,
                Columns    = "NodeID",
                Where      = String.Format("DocumentPageTemplateID = {0} OR NodeTemplateID = {0} OR NodeWireframeTemplateID = {0}", PageTemplate.PageTemplateId)
            };

            DataSet ds = tp.SelectNodes(parameters);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                result = GetString("template.dahsboardliveused");
            }

            // Check valid zones
            if (String.IsNullOrEmpty(result))
            {
                PageTemplateInstance inst = PageTemplate.TemplateInstance;
                if (inst != null)
                {
                    foreach (WebPartZoneInstance zone in inst.WebPartZones)
                    {
                        switch (zone.WidgetZoneType)
                        {
                        case WidgetZoneTypeEnum.Dashboard:
                        case WidgetZoneTypeEnum.None:
                            continue;
                        }

                        result = GetString("template.dashboardinvalidzone");
                        break;
                    }
                }
            }
        }

        if (String.IsNullOrEmpty(result))
        {
            // Update page template info
            PageTemplate.DisplayName = txtTemplateDisplayName.Text;
            PageTemplate.CodeName    = txtTemplateCodeName.Text;
            PageTemplate.Description = txtTemplateDescription.Text;
            PageTemplate.CategoryID  = Convert.ToInt32(categorySelector.Value);

            if (SelectedPageType == PageTemplateTypeEnum.MVC)
            {
                // MVC template
                PageTemplate.IsPortal = false;
                PageTemplate.FileName = String.Empty;

                PageTemplate.ShowAsMasterTemplate     = false;
                PageTemplate.PageTemplateCloneAsAdHoc = false;

                PageTemplate.PageTemplateDefaultController = txtController.Text;
                PageTemplate.PageTemplateDefaultAction     = txtAction.Text;
            }
            else if (SelectedPageType == PageTemplateTypeEnum.Portal)
            {
                // Portal template of various types
                PageTemplate.IsPortal = true;
                PageTemplate.FileName = String.Empty;

                // Save inherit levels
                if (!chkShowAsMasterTemplate.Checked)
                {
                    PageTemplate.InheritPageLevels = ValidationHelper.GetString(lvlElem.Value, "");
                }
                else
                {
                    PageTemplate.InheritPageLevels = "/";
                }

                // Show hide inherit levels radio buttons
                PageTemplate.ShowAsMasterTemplate     = chkShowAsMasterTemplate.Checked;
                PageTemplate.PageTemplateCloneAsAdHoc = chkAdHoc.Checked;
            }
            else
            {
                // ASPX page templates
                PageTemplate.IsPortal = false;
                PageTemplate.FileName = FileSystemSelector.Value.ToString();

                PageTemplate.ShowAsMasterTemplate     = false;
                PageTemplate.PageTemplateCloneAsAdHoc = false;

                PageTemplate.InheritPageLevels = "";
            }

            PageTemplate.PageTemplateType = SelectedPageType;

            // Set ad-hoc status
            PageTemplate.IsReusable = pageTemplateIsReusable;
            if (pageTemplateIsReusable)
            {
                PageTemplate.PageTemplateNodeGUID = Guid.Empty;
            }

            PageTemplate.WebParts = pageTemplateWebParts;

            try
            {
                // Save the template and update the header
                PageTemplateInfoProvider.SetPageTemplateInfo(PageTemplate);
                ScriptHelper.RegisterStartupScript(this, typeof(string), "pageTemplateSaveScript", ScriptHelper.GetScript("RefreshContent()"));
                ShowChangesSaved();
            }
            catch (UnauthorizedAccessException ex)
            {
                ShowError(ResHelper.GetStringFormat("general.sourcecontrolerror", ex.Message));
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
            }
        }
        else
        {
            rfvTemplateDisplayName.Visible = false;
            rfvTemplateCodeName.Visible    = false;

            ShowError(result);
        }
    }