How do I pass variables to and from a custom dialog box?

Last post 03-30-2006, 1:18 PM by Adam. 3 replies.
Sort Posts: Previous Next
  •  03-28-2006, 6:12 AM 17651

    How do I pass variables to and from a custom dialog box?

    Hi,
     
    I want to create a function where a user selects some text and then clicks a custom button to open a dialog box, makes some selection from the dialog box which subsequently pastes some HTML code to the editor. I'm fine with creating the button, opening a dialog box and then pasting the HTML. The only thing I can't figure out is how to pass a value (in this case the selected text) to the dialog box.
     
    Is there a simple way to do this?
     
    Nick
     
     
  •  03-28-2006, 1:35 PM 17663 in reply to 17651

    Re: How do I pass variables to and from a custom dialog box?

    Nick,
     
        Try:

        // get the cute editor instance
        var editor1 = document.getElementById('<%=Editor1.ClientID%>');
        
        //Get the editor selection
        var editselection=editor1.GetSelection();

     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  03-29-2006, 9:07 AM 17696 in reply to 17663

    Re: How do I pass variables to and from a custom dialog box?

    Hi,
     
    Where should that code be? I get an object is null or undefined error with the following code:
     
    Calling page
     
    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <%@ Page Language="vb" ContentType="text/html" ResponseEncoding="iso-8859-1" debug="true"%>
    <script runat="server">
     Sub Page_Load
            Dim pos As Integer
            pos = Editor1.ToolControls.IndexOf("Italic") + 1
            Dim ctrl As System.Web.UI.WebControls.WebControl
            ctrl = Editor1.CreateCommandButton("MyButton", "text.gif", "Insert My Custom Text")
            ctrl.Attributes("onclick") = "ShowMyDialog(this)"
            Editor1.InsertToolControl(pos, "MyButton", ctrl)
        End Sub
    </script>
    <script language="JavaScript" type="text/javascript" >
     function ShowMyDialog(button)
     {
      //use CuteEditor_GetEditor(elementinsidetheEditor) to get the cute editor instance
      var editor=CuteEditor_GetEditor(button);
      //show the dialog page , and pass the editor as newwin.dialogArguments
      var newwin=showModelessDialog("selectInsert.htm?_rand="+new Date().getTime(),editor,"dialogWidth:400px;dialogHeight:300px");
     }
    </script>
    <html>
        <head>
      <link rel="stylesheet" href="../../example.css" type="text/css" />
     </head>
        <body >
            <form runat="server" ID="Form1">    
       <CE:Editor id="Editor1" runat="server" AutoConfigure="Minimal" FilesPath="CuteSoft_Client/CuteEditor/"></CE:Editor><br />   
      </form>
     </body>
    </html>
     
    Dialog box

    <html>
    <head>
    <title>Select insert</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <form name="frmInserts">
    <label>Select an insert type:</label><br/>
    <table width="200">
      <tr>
        <td>
          <input type="radio" name="radInserts" value="fig">
          Figure</td>
      </tr>
      <tr>
        <td>
          <input type="radio" name="radInserts" value="box">
          Box</td>
      </tr>
      <tr>
        <td>
          <input type="radio" name="radInserts" value="ref">
          Reference</td>
      </tr>
      <tr>
        <td>
          <input type="radio" name="radInserts" value="case">
          Case Study</td>
      </tr>
      <tr>
        <td>
          <input type="radio" name="radInserts" value="note">
          Note</td>
      </tr>
    </table>
    <br/>
    <label>Enter insert reference: </label>
    <input name="txtInsert" type="text">
    <br>
       <button onclick="button_click()">Insert</button>
       <button onclick="window.close()">Close</button>
    </form>
    </body>
    <script>
     function button_click()
     {
      for (i=0; i<frmInserts.radInserts.length; i++) {
       if (frmInserts.radInsertsIdea [I].checked) {
        var strClass = frmInserts.radInsertsIdea [I].value
       }
      }
      // get the cute editor instance
         var editor1 = document.getElementById('<%=Editor1.ClientID%>');
         //Get the editor selection
         var editselection=editor1.GetSelection();
      var strInsert = frmInserts.txtInsert.value;
      var strLink = "<a href='insert.htm?id="+strInsert+"' class='"+strClass+"'>"+editselection+"</a>"
      
      var editor=window.dialogArguments;
      
      editor.ExecCommand("pasteHTML",false,strLink);
     }
     </script>
    </html>
  •  03-30-2006, 1:18 PM 17749 in reply to 17663

    Re: How do I pass variables to and from a custom dialog box?

    Nick,
     
        Try:

        // get the cute editor instance
        var editor1 = document.getElementById('<%=Editor1.ClientID%>');
        
        //Get the editor selection
        var editselection=editor1.GetSelection();

        if(editselection.type=='Control')
        {
        }
        else
        {
              var r=editselection.createRange();
              var html=r.htmlText;   
              alert(html); 
        }

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

View as RSS news feed in XML