Custom Dialog trigger editor.pasteHtml

1 posts, 0 answers
  1. Alan
    Alan avatar
    6 posts
    Member since:
    Feb 2012

    Posted 30 May Link to this post

    I try to make a RadListBox inside the Custom Dialog. I would like to pass the value from RadListBox to parent page when I double clicking on it. I try using editor.pasteHtml funcion in double click event of RadListBox but it won't work.
    Could you please tell me where I went wrong.
    My source code like below.

    WebForm.aspx

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebEditor.WebForm1" %>
     
    <!DOCTYPE html>
     
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                    <Scripts>
                        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
                    </Scripts>
                </telerik:RadScriptManager>
                <script>    
                    
                    Telerik.Web.UI.Editor.CommandList["InsertLexicon"] = function (commandName, editor, args) {
                        var myCallbackFunction = function (sender, args) {
                            editor.pasteHtml(args.image);
                        }
     
                        editor.showExternalDialog(
                        "InsertLexicon.aspx",
                        {},
                        400,
                        560,
                        myCallbackFunction,
                        null,
                        "InsertLexicon",
                        true,
                        Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move,
                        false,
                        true);
                    };
     
                    function pasteLexicon(myData)
                    {               
                        var editor = $find('<%= edComment.ClientID%>');
                        editor.pasteHtml(myData);
                    }
                </script>
                <br />
                <br />
                <br />
           <br />
                <telerik:RadEditor RenderMode="Lightweight" runat="server" ID="edComment" EditType="Inline" NewLineMode="Br" ToolsFile="ToolsFile.xml">
                </telerik:RadEditor>
                
            
            </div>
        </form>
    </body>
    </html>

     

    InsertLexicon.aspx

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="InsertLexicon.aspx.vb" Inherits="WebEditor.InsertLexicon" %>
     
    <!DOCTYPE html>
     
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <link href="StyleSheets/Editor.css" rel="stylesheet" type="text/css" />
        <title>InsertLexicon</title>
     
    </head>
    <body>
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                <Scripts>
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
                </Scripts>
            </telerik:RadScriptManager>
            <script type="text/javascript">
                function getRadWindow() //mandatory for the RadWindow dialogs functionality
                {             
                    if (window.radWindow) {
                        return window.radWindow;
                    }
                    if (window.frameElement && window.frameElement.radWindow) {
                        return window.frameElement.radWindow;
                    }
                    return null;
                }
     
                function initDialog() //called when the dialog is initialized
                {
                    var clientParameters = getRadWindow().ClientParameters;
                }
     
                if (window.attachEvent) {
                    window.attachEvent("onload", initDialog);
                }
                else if (window.addEventListener) {
                    window.addEventListener("load", initDialog, false);
                }
     
                function insertLexicon() //fires when the Insert Link button is clicked
                {
                    var closeArgument = {};
                    var list = $find("<%= listComment.ClientID%>");
                    var item = list.get_selectedItem();
                    if (item == null || item == undefined) {
                        alert("請選擇詞庫");
                        return false;
                    }
                    else {
                        closeArgument.image = item.get_value();
                        getRadWindow().close(closeArgument);
                    }
                }
     
                function closeWindow() {
                    getRadWindow().close();
                }
     
                function OnClientItemDoubleClicked(sender, args)
                {                  
                    var closeArgument = {};
                    var list = $find("<%= listComment.ClientID%>");
                    var item = list.get_selectedItem();
                    getRadWindow().get_browserWindow().pasteLexicon(item.get_value());           
                }
                
            </script>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            </telerik:RadAjaxManager>
     
          <!--Tool-->           
            <telerik:RadListBox RenderMode="Lightweight" runat="server" ID="listComment" Height="350px" Width="100%"  ButtonSettings-AreaWidth="35px"
              OnClientItemDoubleClicked="OnClientItemDoubleClicked">
                <Items>
                    <telerik:RadListBoxItem Text="Value1" Value="value1"></telerik:RadListBoxItem>
                    <telerik:RadListBoxItem Text="Value2" Value="Value2"></telerik:RadListBoxItem>
                </Items>
            </telerik:RadListBox>
            <br />   
            <div >
                <telerik:RadButton RenderMode="Lightweight" AutoPostBack="false" ID="RadButton6" runat="server" OnClientClicked="insertLexicon" Text="Save" />
                <telerik:RadButton RenderMode="Lightweight" AutoPostBack="false" ID="RadButton7" runat="server" OnClientClicked="closeWindow" Text="Close" />
            </div>
        </form>
    </body>
    </html>

Back to Top