Placing a custom button anywhere inside the bar of buttons causes the text value to be incorrect

Last post 08-28-2007, 10:44 AM by Aldo. 8 replies.
Sort Posts: Previous Next
  •  08-23-2007, 9:20 AM 32751

    Placing a custom button anywhere inside the bar of buttons causes the text value to be incorrect

    I don't know if you can help with this. It is a bit of a strange bug. We have been trying to add a custom button (to generate our own insert link popup - connecting to pages in the database). Everything works fine, unless we actually place the custom button anywhere inside the bar with the rest of the buttons. As long as it is either above it or bellow it things will work however.

    What happens is that the value of the editor can not be read anymore the .text value won't include thing added in there anymore. Unless it was already in there on load. To illustrate in our CMS:

    1) We load a page from the database. It's current content is loaded inside the cuteeditor so a user can change it.
    2) The user makes changes
    3) the user saves

    (same idea for a new page, then an empty cuteeditor will display)

    Now if we include a custom button the editor's text property just won't have any new text. If the text before was "Hello world" and I added 'Hello wonderfull world" it would on postback again be "Hello world".

    If we add the custom button above or bellow the other standard buttons. Then everything saves just fine. We have tried multiple ways to add the button and to create the button. Incl. from various examples found on the support forum. I will copy/paste just one of ways we tried to illustrate (ceEditor is the cuteeditor).

    This works fine:
            WebControl ctrl = ceEditor.CreateCommandButton("MyButton", "link.gif", "Insert My Custom Link");
            ctrl.Attributes["onclick"] = "var popUp = openPop();CuteEditor_GetEditor(this).ExecCommand('PasteHTML',false,popUp); ";
            this.ceEditor.InsertToolControl(0, "MyButton", ctrl);

    This already stops working:
            Button bcLink = new Button();
            bcLink.Text = "Link";
            System.Web.UI.Control container = this.ceEditor.ToolControls[0].Control;
            container.Controls.Add(bcLink);

    Sorry for the bad examples. It's been an entire day of trying out various things so not all code has been saved. We've also tried to add it through the config. Same problem. Just as soon as we in any possible way add a custom button "among the other buttons" it goes wrong. When it get's it's own "line" so to say, it works fine.

  •  08-23-2007, 9:36 AM 32756 in reply to 32751

    Re: Placing a custom button anywhere inside the bar of buttons causes the text value to be incorrect

    Aldo,
     
    There are two types of custom button, client side or server side. The server side will trigger a postback. Please check the following two examples:
     
    Add a Cross Browser Modal Dialog Box to Cute Editor

    How to create a custom button(client side) which displays a dialog?( C# | VB )

    This example demonstrates how easy it can be to add your own client side buttons to the CuteEditor by creating a Cross Browser Modal Dialog Box.

    create/register a custom button (Server Control) to Cute Editor

    How to create/register a custom button (Server Control) so that it can be used in the template?( C# | VB )

    This example demonstrates how easy it can be to add Server Controls to the CuteEditor and register it into Cute Editor toolbar.

     
     
    I think for your situation, you should go with the first example. You can find the source of this example in the download package.
     
     

    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

  •  08-23-2007, 10:39 AM 32765 in reply to 32756

    Re: Placing a custom button anywhere inside the bar of buttons causes the text value to be incorrect

    Hi Adam,
     
    It's nice to get a response so quickly.
    I have tried inserting the custom button using the "insertToolControl". it worked fine.
    But apparently the ToolControl takes quite a lengthy space. i wanted to insert my button next to the "unlink" control.
    The "InsertToolControl" however adds quite a lengthy empty spaces.
     
    Thank you in advance,
     
     
    Aldo
  •  08-23-2007, 10:47 AM 32768 in reply to 32765

    Re: Placing a custom button anywhere inside the bar of buttons causes the text value to be incorrect

    Aldo,
     
    use the following method:

      //about Italic, see Full.config
      //<item type="image" name="Italic" imagename="Italic" />
      //get the pos after the Italic

      int pos=Editor1.ToolControls.IndexOf("Italic")+1;

      //Themes/%ThemeName%/Images/text.gif
      WebControl ctrl=Editor1.CreateCommandButton("MyButton","text.gif","Insert My Custom Text");

      ctrl.Attributes["onclick"]="ShowMyDialog(this)";
     
      //add this custom button into the editor
      Editor1.InsertToolControl(pos,"MyButton",ctrl);
     

    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

  •  08-24-2007, 3:42 AM 32828 in reply to 32768

    Re: Placing a custom button anywhere inside the bar of buttons causes the text value to be incorrect

    Hi Adam,
     
    I used your method, but the content saving failed. The text property of the editor did not update.
    however if i assigned pos = 0 instead of getting the position from the "IndexOf" method, it works fine.
    but pos = 0 is not the position i intended to put my custom button.
    Is there something i missed?
     
     
     
    Kind Regards,
     
    Aldo
  •  08-24-2007, 10:11 AM 32841 in reply to 32828

    Re: Placing a custom button anywhere inside the bar of buttons causes the text value to be incorrect

    Aldo,
     
    Can you try the following example?
     
    create/register a custom button (Server Control) to Cute Editor

    How to create/register a custom button (Server Control) so that it can be used in the template?( C# | VB )

    This example demonstrates how easy it can be to add Server Controls to the CuteEditor and register it into Cute Editor toolbar.

     
    You can find the source code of this example in the download package. It's under "advanced topics" section.
     
    Framework 1.x\HowTo\AddDialogs\cs
    Framework 1.x\HowTo\AddDialogs\vb
    Framework 2.0\HowTo\AddDialogs\cs
    Framework 2.0\HowTo\AddDialogs\vb
     
    Please make sure you can run this example successfully, then modify it to meet your requirements.
     
     
     

    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

  •  08-28-2007, 6:21 AM 32979 in reply to 32841

    Re: Placing a custom button anywhere inside the bar of buttons causes the text value to be incorrect

    Hi Adam,
     
    I tried the example. the custom button placed correctly but the text value of the editor becomes incorrect.
     
     
     
     

  •  08-28-2007, 6:48 AM 32980 in reply to 32979

    Re: Placing a custom button anywhere inside the bar of buttons causes the text value to be incorrect

    Adam,
     
    Something a bit weird is happening:
     
    int pos = 0; // Editor1.ToolControls.IndexOf("Italic")+1;
    WebControl ctr = Editor1.CreateCommand Button.......
    ...................................
    Editor1.InsertToolControl(pos,"MyButton",ctr);
     
     
    When i uncomment the "Editor1....." to fill in the pos variable, the Text property of the editor becomes incorrect.
    But when i use "0", it works fine. it looks like the "Editor.ToolControls.IndexOf("Italic")+1 " is causing the error.
  •  08-28-2007, 10:44 AM 32990 in reply to 32841

    Re: Placing a custom button anywhere inside the bar of buttons causes the text value to be incorrect

    Hi Adam,

    I think we found why it is going wrong and fixed it. I'll try and explain.

    Say we have
    int pos = 0;
    ceEditor.InsertToolControl(pos, "MyButton", ctrl);

    The above will work fine.

    Now we change it to:

    int pos = ceEditor.ToolControls.IndexOf("Unlink") + 1;
    ceEditor.InsertToolControl(pos, "MyButton", ctrl);

    We can't save our content anymore.

    Say that the pos it gave back was 20 (as an example) So just to test we say:

    int pos = 20;
    ceEditor.InsertToolControl(pos, "MyButton", ctrl);

    Now the entire editor will crash! It won't just not save our current content, but it actually crashes on build up. Odd one would say given that if we before using ToolControls.IndexOf had been given a position of 20 we should be able to add it directly as well not? Well...

    If we do this:
    int pos = ceEditor.ToolControls.IndexOf("Unlink") + 1;
    pos = 0;
    ceEditor.InsertToolControl(pos, "MyButton", ctrl);


    The result becomes that the editor will be build up without it crashing, but we can not save our contents anymore.

    In short, it seems that ToolControls.IndexOf() does something more then just give us back an Index. it somehow changes the ceEditor object to allow us to insert a control somewhere inbetween. And that is exactly the problem why our text disapears.

    Our ceEditor is an Object nested 3 deep inside user controls. We have an Admin.aspx which can create an Editor User Control, which can create 0, 1 or multiple "Wysiwyg" user controls. That last control has the CuteEditor for us. So it's nested quite deep. This for us is needed as the admin.aspx can build up different things then just the editor to edit websites in. And the editor itself can dynamically based on what page it edits change itself to include 0 to n CuteEditors.

    We checked the ID with and without ToolControls.IndexOf being called and this is what happens:

    Without ToolControls.IndexOf() the ID of the Editor is:
    BecoCMSEditor$inhoud$ceEditor

    Which is good. That means we talk to the same object later on when saving.

    Now we call ToolControls.IndexOf() in some way and the ID of the Editor becomes:

    inhoud$ceEditor

    So the object has been changed just by calling ToolControls.IndexOf().

    Due to this it seems that we can't call the original .text property anymore. Now part of this of course is our own problem. But it's puzzling why the ID and CuteEditor object seems to be modified to find an Index. And without doing that the object refuses to accept any inserts except at the start of it. We managed to fix it by adding the button directly on creation of the user object, while it's ID is set later after creation. Before we both added the button and set it's ID after creation.


View as RSS news feed in XML