Support forums
in

Custom Button pasteing Javascript

Last post 11-08-2008, 2:20 AM by Kenneth. 5 replies.
Sort Posts: Previous Next
  •  11-04-2008, 3:40 PM 45391

    Custom Button pasteing Javascript


     
    My question is how do create a custome button to paste javascript?
    I am trying to paste the javascript code in the body.
     

    WebControl ctrl = Editor1.CreateCommandButton("MyButton", "MyButton.png", "Insert MyButton");

    ctrl.Attributes["onclick"] = "CuteEditor_GetEditor(this).ExecCommand('PasteHTML',false,' <script>document.write('Hello World!');</script>')";

  •  11-04-2008, 11:31 PM 45394 in reply to 45391

    Re: Custom Button pasteing Javascript

    Hi jbucknor,
     
     
    Try this example:
     

    <%@ Page Language="C#" %>

    <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            WebControl ctrl = Editor1.CreateCommandButton("MyButton", "text.gif", "Insert My Custom Text");
            ctrl.Attributes["onclick"] = "CuteEditor_GetEditor(this).ExecCommand('PasteHTML',false,'<h2>Hello World</h2>')";
            Editor1.RegisterCustomButton("mybutton", ctrl);
        }

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <CE:Editor ID="Editor1" runat="server" TemplateItemList="[Bold,Italic]/[mybutton]">
                </CE:Editor>
            </div>
        </form>
    </body>
    </html>
     
     
    Regards,
     
    Ken
  •  11-05-2008, 12:28 PM 45437 in reply to 45394

    Re: Custom Button pasteing Javascript

    It is not that I want to write "hello world" to the the document, I want to past <script></script> tags in the html when the button is clicked.
  •  11-05-2008, 10:19 PM 45444 in reply to 45437

    Re: Custom Button pasteing Javascript

    Hi jbucknor,
     
     
    Try this example:
     

    <%@ Page Language="C#" %>

    <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            WebControl ctrl = Editor1.CreateCommandButton("MyButton", "text.gif", "Insert My Custom Text");
            string myString = "<script><" + "/script>";
            ctrl.Attributes["onclick"] = "CuteEditor_GetEditor(this).ExecCommand('PasteHTML',false,'"+myString+"')";
            Editor1.RegisterCustomButton("mybutton", ctrl);
        }

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <CE:Editor ID="Editor1" runat="server" TemplateItemList="[Bold,Italic]/[mybutton]" EnableStripScriptTags="False">
                   
                </CE:Editor>
       
            </div>
        </form>
    </body>
    </html>

     
    Regards,
     
    Ken
  •  11-06-2008, 3:39 PM 45483 in reply to 45444

    Re: Custom Button pasteing Javascript

    Ken,
     
    I copied that code out and it did not work. Did it work for you?
  •  11-08-2008, 2:20 AM 45530 in reply to 45483

    Re: Custom Button pasteing Javascript

    Hi jbucknor,
     
     
    Try this code please:
     

    <%@ Page Language="C#" %>

    <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            WebControl ctrl = Editor1.CreateCommandButton("MyButton", "text.gif", "Insert My Custom Text");
            string myString = "<script>document.write(\"Hello World!\")<" + "/script>";
           
            ctrl.Attributes["onclick"] = "CuteEditor_GetEditor(this).ExecCommand('PasteHTML',false,'"+myString+"')";
            Editor1.RegisterCustomButton("mybutton", ctrl);
        }

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <CE:Editor ID="Editor1" runat="server" TemplateItemList="[Bold,Italic]/[mybutton]" EnableStripScriptTags="False">
                   
                </CE:Editor>
       
            </div>
        </form>
    </body>
    </html>

     
    Regards,
     
    Ken
View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems