Adding Editor Programmatically: Missing Scripts

5 posts, 0 answers
  1. Jeff
    Jeff avatar
    51 posts
    Member since:
    Aug 2007

    Posted 08 Sep 2009 Link to this post

    Hello,

    I need to add the Editor to the page programmatically. When I do, I end up missing about a dozen scripts that I would normally see when the editor is inline in the aspx. Because of the missing scripts, I get "Telerik is not defined."

    Here's how I'm adding the control. Can you tell me what else I should be doing?

    Thanks,
    Jeff

        protected void Page_Load(object sender, EventArgs e) 
        { 
            // "Content" is a ContentPlaceHolder in a master page 
            Content.Controls.Add(InitializeEditor()); 
     
            // Add inline scripts for handling commands. etc. 
            RegisterScripts(); 
     
                    // Contains 'EditorLoaded' function, filters, etc. 
            litEditorScript.Text = 
                string.Format("<script src=\"{0}{1}\" type=\"text/javascript\"></script>"
                    URLs.RootPath, "js/ControlsEditMode.js"); 
        } 
     
        private RadEditor InitializeEditor() 
        { 
            RadEditor re = new RadEditor(); 
     
            re.ContentFilters = EditorFilters.RemoveScripts | EditorFilters.FixEnclosingP | EditorFilters.FixUlBoldItalic | 
                EditorFilters.MozEmStrong | EditorFilters.ConvertFontToSpan | EditorFilters.ConvertFontToSpan | 
                EditorFilters.IndentHTMLContent; 
            re.ContentAreaCssFile = "~/Sitefinity/Admin/Themes/Default/AjaxControlsSkins/Sitefinity/EditorContentArea.css"
            re.ToolsFile = "~/Sitefinity/Admin/ControlTemplates/EditorToolsFile.xml"
            re.Skin = "Office2007"
            re.NewLineBr = false
            re.OnClientPasteHtml = "OnClientPasteHtml"
            re.OnClientLoad = "EditorLoaded"
            //Css, Font, MSWordRemoveAll 
            re.StripFormattingOptions = EditorStripFormattingOptions.Css | EditorStripFormattingOptions.Font | 
                EditorStripFormattingOptions.MSWordRemoveAll; 
     
            re.CssFiles.Add("~/style.css"); 
            re.CssFiles.Add("~/designer.css"); 
     
            re.FlashManager.DeletePaths = new string[] { "~/Files" }; 
            re.FlashManager.UploadPaths = new string[] { "~/Files" }; 
            re.FlashManager.ViewPaths = new string[] { "~/Files" }; 
     
            re.ImageManager.DeletePaths = new string[] { "~/Images" }; 
            re.ImageManager.UploadPaths = new string[] { "~/Images" }; 
            re.ImageManager.ViewPaths = new string[] { "~/Images" }; 
     
            re.DocumentManager.DeletePaths = new string[] { "~/Files" }; 
            re.DocumentManager.UploadPaths = new string[] { "~/Files" }; 
            re.DocumentManager.ViewPaths = new string[] { "~/Files" }; 
     
            re.MediaManager.DeletePaths = new string[] { "~/Files" }; 
            re.MediaManager.UploadPaths = new string[] { "~/Files" }; 
            re.MediaManager.ViewPaths = new string[] { "~/Files" }; 
     
            return re; 
        } 
     
        private void RegisterScripts() 
        { 
            Type cstype = GetType(); 
            ClientScriptManager cs = Page.ClientScript; 
            string strPageEditorInline = HttpContext.Current.Server.MapPath(URLs.RootPath + "Sitefinity/Admin/Scripts/PageEditorInline.js"); 
     
            // Check to see if the client script is already registered. 
            if (!cs.IsClientScriptBlockRegistered(cstype, "PageEditorInline") && 
                File.Exists(strPageEditorInline)) 
                cs.RegisterClientScriptBlock(cstype, "PageEditorInline"
                    File.ReadAllText(strPageEditorInline), true); 
     
        } 
  2. Jeff
    Jeff avatar
    51 posts
    Member since:
    Aug 2007

    Posted 09 Sep 2009 Link to this post

    I'd like to add that I am including the the ScriptManager in the aspx page like so:

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 

    Are there any other managers I need to add?


  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 11 Sep 2009 Link to this post

    Hi Jeff,

    You should make sure that the problem is not due to your own scripts. They should not be registered before the registration of the RadEditor's scripts.
    My suggestion is to comment the RegisterScripts(); method and see whether the problem still persists.

    You do not need any other managers on the page except the <asp:ScriptManager>.

    Sincerely yours,
    Rumen
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Jeff
    Jeff avatar
    51 posts
    Member since:
    Aug 2007

    Posted 11 Sep 2009 Link to this post

    Hi Rumen,

    You're right- if I don't register my scripts, the 12 scripts that RadEditor registers are present in the HTML and I don't get the error.

    This leads to the question: How do I properly register my scripts while simultaneously allowing RadEditor to register its scripts?

    Is there a post or manual page that explains this technique?

    Thanks,
    Jeff
  6. Jeff
    Jeff avatar
    51 posts
    Member since:
    Aug 2007

    Posted 11 Sep 2009 Link to this post

    Never mind, I figured it out on my own.

    The trick was to register my inline scripts (for toolbar button handling, etc) as a StartUpScript rather than a ClientScriptBlock.

    Even through it's not technically a script intended to run on startup, using the StartUpScript call ensures the script is placed at the bottom of the HTML stream. The 12 RadEditor scripts show up shortly after the opening <body> element.

    The new block of code in RegisterScripts() looks like this:

            // Check to see if the client script is already registered. 
            if (!cs.IsStartupScriptRegistered(cstype, "PageEditorInline") && 
                File.Exists(strPageEditorInline)) 
                cs.RegisterStartupScript(cstype, "PageEditorInline"
                    File.ReadAllText(strPageEditorInline), true); 
     


    Thanks for pointing me in the right direction.

    Jeff


Back to Top
UI for ASP.NET Ajax is Ready for VS 2017