Get FileName from Template Manager

5 posts, 1 answers
  1. Jack
    Jack avatar
    128 posts
    Member since:
    May 2003

    Posted 06 Feb 2013 Link to this post

    Hi,

    I have an Editor with the Template Manager in the tools.
    What I need to do is that when a user select a template from the manager - a Textbox is populated with the name of that file.

    Basically I am creating a template Save and Manage Area, so I need the name of the selected template.

    All help appreciated.

    Cheers,

    Jon
  2. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 07 Feb 2013 Link to this post

    Hi,

    You can easily get the url of the selected and inserted template file using the this._currentItem.getUrl() property in the getResult function in the \EditorDialogs\TemplateManager.ascx control. To supply this information from the dialog to the main page add window.top.invokeTopPageMethod(this._currentItem.getUrl()); , e.g.

    getResult : function()
    {
    if (this._currentItem && this._currentItem.type == Telerik.Web.UI.Widgets.FileItemType.File && this.isValidExtension())
    {
    //HACK: Provide the name to the parent page so that it can be further recorded into a database
    window.top.invokeTopPageMethod(this._currentItem.getUrl());

    return this._currentTemplateItem.contentWindow.document.body.innerHTML;
    }
    return null;
    },


    and on the main page with the editor add the following function:

    < script type="text/javascript">
    function invokeTopPageMethod (fileName)
    {

        alert("The template file name selected was " + filePath);
    }
    < /script>
    < telerik:RadEditor runat="server" ExternalDialogsPath ="~/EditorDialogs"
    ID="RadEditor1">
    <TemplateManager ViewPaths="~/" UploadPaths="~/" />
    < /telerik:RadEditor>


    Regards,
    Rumen
    the Telerik team
    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 their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jack
    Jack avatar
    128 posts
    Member since:
    May 2003

    Posted 08 Feb 2013 Link to this post

    Hi Rumen,

    Thanks for this but I can't get it going.

    I have this in the dialog

    getResult : function()
        {
            if (this._currentItem && this._currentItem.get_type() == Telerik.Web.UI.FileExplorerItemType.File)
            {
                window.top.invokeTopPageMethod(this._currentItem.getUrl());
                return this._currentTemplateItem.contentWindow.document.body.innerHTML;
            }
            return null;
        },

    and this on the page

    <script type="text/javascript">
    function invokeTopPageMethod (fileName)
    {
        alert("The template file name selected was " + filePath);
    }
    </script>
     
    <telerik:radeditor runat="server" ID="reTemplates"  Height="600"  Width="984px" Skin="Metro"  EditModes="Design" 
    DialogHandlerUrl
    ="~/Telerik.Web.UI.DialogHandler.axd"  TemplateManager-SearchPatterns="*.html, *.htm, *.txt"
    ImageManager-SearchPatterns="*.gif, *.jpg, *.jpeg, *.png" ContentAreaMode="Div"
    ExternalDialogsPath="~/_admin/editorDialogs">

    when I add in the code

    window.top.invokeTopPageMethod(this._currentItem.getUrl());

    it stops the insert function of the template manager I'm afraid.

    Would you perhaps have a sample?

    Many thanks,
    Jon
  5. Answer
    Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 08 Feb 2013 Link to this post

    Hi,

    I have a typo in the name of this method getUrl(), which should be get_url(). getUrl is old syntax which is not supported in the latest version.

    For your convenience I have attached a sample working project.

    All the best,
    Rumen
    the Telerik team
    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 their blog feed now.
  6. Jack
    Jack avatar
    128 posts
    Member since:
    May 2003

    Posted 08 Feb 2013 Link to this post

    Hi Rumen,

    That's fantastic - Works like a charm!
    Thank you very much.

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