Render the Javascript only

3 posts, 0 answers
  1. Bill
    Bill avatar
    9 posts
    Member since:
    Jun 2013

    Posted 07 Jul 2014 Link to this post


    I am switching between the kendo editor and plain text using jquery. I'm destroying the kendoEditor and then removing it from the DOM in such a way that the textarea is left behind. Then if I need to switch back to the editor I call $("#Test").kendoEditor() again. This works pretty well so far.

    My first question is: Is there a simpler way of doing this?

    My second question is: I'd like to write out the Javascript that converts the textarea to an editor only once. Is there a way to tell the Html helper to render just the javascript so I can put the output into a function?

    For example. @Html.Kendo().Editor().Name("Test").Encode(false) will write out both the textarea and the javascript. Can I get it to write just the javascript?

    Many thanks,
  2. Dimo
    Dimo avatar
    8407 posts

    Posted 09 Jul 2014 Link to this post

    Hello Bill,

    An alternative approach to destroying and recreating the Editor is to use separate textarea and Editor widget, and toggle their visibility. This is not necessary simpler or better - it depends on your scenario and implementation.

    The Kendo UI server wrappers are designed to render both the required HTML markup and Javascript initialization statement and this cannot be changed. Theoretically, you have an option to hack the widget like this:

    Capture the widget HTML output and defer the script output, so that they are not rendered immediately and automatically. Then render the HTML and/or script outputs separately where you want them to be. You will also be able to manipulate the output via standard string operations. The Html.Raw() statements are required in order to render the HTML and scripts non-encoded.

      var widgetHtml = Html.Kendo().Editor().Name("editor").Deferred().ToString();
      var widgetScript = Html.Kendo().DeferredScripts(false).ToString();
      // some JS code before
      // some JS code after


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. Bill
    Bill avatar
    9 posts
    Member since:
    Jun 2013

    Posted 11 Jul 2014 in reply to Dimo Link to this post

    Hi Dimo

    Using Deferred and DeferredScripts did exactly what I needed. Thanks very much!

Back to Top