Insert Template from code behind

2 posts, 0 answers
  1. Rishi
    Rishi avatar
    43 posts
    Member since:
    Feb 2010

    Posted 23 Oct 2013 Link to this post


    I was trying to achieve the following with no much success

    I want to insert one of the templates into the radeditor content from code behind.
    I was not able to figure out what properties I have to access to pick the right template and assign it to the RadEditor textbox content ?

  2. Ianko
    Ianko avatar
    1956 posts

    Posted 24 Oct 2013 Link to this post

    Hello Harisha,

    The desired functionality cannot be implemented with built-in properties. From the code behind the editor is expected to be set with an ordinary string value by design.

    You could use a custom implementation, which gets the html file, retrieve its content as text and sets the editor's content with the value of the body elements.

    This is an example code, which is working fine on my end:
    string mslinepath = Server.MapPath("TemplateFolder/template.html");
    string htmlCode = File.ReadAllText(mslinepath);
    int startIndex = htmlCode.IndexOf("<body");
    int endIndex = htmlCode.IndexOf("</html>");
    string content = htmlCode.Substring(startIndex, endIndex - startIndex);
    RadEditor1.Content = content;

    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top