Styles and OnCommand events clearing on postback

Last post 01-22-2014, 7:41 PM by gazza666. 2 replies.
Sort Posts: Previous Next
  •  01-22-2014, 3:28 AM 78800

    Styles and OnCommand events clearing on postback

    Every time I do a postback, the CE:Editor class loses all the customisations that I've made:

    • Reconfiguring the toolbar. This is merely an annoyance, as I can reset the toolbar on every postback.
    • No longer traps the CuteEditor_OnCommand javascript event. This is what I'm trying to fix.

    Here's my use case: I have a form where the user can select from a drop down list that names various images that are available. All of these are stored in a SQL database. I want to be able to trap the OnCommand event so that if they have selected InsertImage, I can have my custom code insert an <img> link instead of bringing up the usual "pick from these uploaded images" option.

     

     My javascript is essentially:

            function CuteEditor_OnCommand(editor, command, ui, value) {

                alert("Command is " + command);

                if (command == "InsertImage") {

                    alert("HERE");

                    insertImage();

                    return true;

                }

                return false;

            }

     

     insertImage is my method. I've left in the alerts for illustrative purposes; as you can see, the basic idea is that the InsertImage command is hijacked, and all others should pass through. When I first load the page, this works fine. But if I use anything that triggers a postback, then from that point onwards this javascript no longer gets executed.

     

    I suspect that I need to restore the callback when I reapply all the configuration changes, but I'm not sure what the property is. I'm also not 100% certain what version of CuteEditor this is, as I'm not sure where that information is stored, but I believe it's version 6.

     

    Any ideas? I'd be ecstatic if someone could clue me in on how to avoid losing everything on postbacks, but I'd be reasonably happy if I could just find a workaround to restore the javascript client event. 

  •  01-22-2014, 8:15 AM 78804 in reply to 78800

    Re: Styles and OnCommand events clearing on postback

    Hi,

     

    Can you try the example page below on your site? Does it get the same problem? If yes, can you send me this example page url? So I can check on it directly. 

     

    1. <%@ Page Language="C#" %>  
    2.   
    3. <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    5. <html xmlns="http://www.w3.org/1999/xhtml">  
    6. <head id="Head1" runat="server">  
    7.     <title>example</title>  
    8. </head>  
    9. <body>  
    10.     <form id="form1" runat="server">  
    11.         <CE:Editor ID="editor1" runat="server">  
    12.         </CE:Editor>  
    13.         <asp:Button ID="btn_PostBack" runat="server" Text="PostBack" />  
    14.         <script type="text/javascript">  
    15.         function CuteEditor_OnCommand(editor,command,ui,value)  
    16.          {  
    17.            if(command=="InsertImage")  
    18.            {  
    19.            alert("insert image");  
    20.            }  
    21.         }  
    22.         </script>  
    23.   
    24.     </form>  
    25. </body>  
    26. </html>  
     

    Regards,

     

    Ken 

  •  01-22-2014, 7:41 PM 78811 in reply to 78804

    Re: Styles and OnCommand events clearing on postback

    Kenneth:

    Hi,

     

    Can you try the example page below on your site? Does it get the same problem? If yes, can you send me this example page url? So I can check on it directly. 

     

    Hi Ken

     

    The significant difference here appears to be that you declare the javascript function after the editor control. Mine was declared in the head section; upon moving it down underneath the editor control it does indeed appear to work! Thank you for your assistance. 

View as RSS news feed in XML