Create Popup on Icon (image) Click

Last post 07-14-2006, 11:24 AM by JonE. 4 replies.
Sort Posts: Previous Next
  •  07-13-2006, 2:22 PM 20972

    Create Popup on Icon (image) Click

    I'm trying to code the editor so that when someone clicks the 'New' icon they get a javascript popup that asks if they really want to clear the document.  I realize they could just hit the 'undo' icon, but you know users aren't that smart sometimes.  If I use the following code, I can easily attach my javascript method to the button...
     
    CType(oCuteEditor.ToolControls("New").Control, System.Web.UI.WebControls.WebControl).Attributes.Add("onclick", "return ConfirmWindow(""Are you sure you want to clear this document??\nSelect 'OK' to delete or 'Cancel' to quit."");")
     
    The problem is that if I add the above 'onclick' event to the image, it no longer functions as a CuteEditor 'New' button, regardless if they select 'ok or 'cancel' in my javascript window.  My javascript window appears, but the editor document doesn't clear.  Is there a way to do this differently?  This works fine for all of my custom pages and any visual studio built-in control.
     
    Here is the Javascript that the above control is attached to.  It returns either true or false.  
     
    <script language="javascript">
    <!--
    function ConfirmWindow(strDialogMessage){
    var strMessage;
    var intResponse;
    intResponse = confirm(strDialogMessage);
    if (intResponse == 1) {
    return true;
    } else {
    return false;
    }
    }
    //-->
    </script>
     
    Thanks in advance,
    Jon
  •  07-13-2006, 3:04 PM 20973 in reply to 20972

    Re: Create Popup on Icon (image) Click

    Jon,
     
    The above solution will not work.
     
    CType(oCuteEditor.ToolControls("New").Control, System.Web.UI.WebControls.WebControl).Attributes.Add("onclick", "return ConfirmWindow(""Are you sure you want to clear this document??\nSelect 'OK' to delete or 'Cancel' to quit."");")
     
    The above code will ovewrite the 'onclick' event of the "New" button.
     
    I suggest you create a new custom button to handle this.
     
    <script language="javascript">
    <!--
    function ConfirmWindow(strDialogMessage){
    var strMessage;
    var intResponse;
    intResponse = confirm(strDialogMessage);
    if (intResponse == 1) {
          
        // get the cute editor instance
        var editor1 = document.getElementById('<%=Editor1.ClientID%>');
       editor1.ExecCommand("New");

    return true;
    } else {
    return false;
    }
    }
    //-->
    </script>
     
     
     
     

    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

  •  07-13-2006, 3:04 PM 20974 in reply to 20972

    Re: Create Popup on Icon (image) Click

    Jon,
     
    The above solution will not work.
     
    CType(oCuteEditor.ToolControls("New").Control, System.Web.UI.WebControls.WebControl).Attributes.Add("onclick", "return ConfirmWindow(""Are you sure you want to clear this document??\nSelect 'OK' to delete or 'Cancel' to quit."");")
     
    The above code will ovewrite the 'onclick' event of the "New" button.
     
    I suggest you create a new custom button to handle this.
     
    <script language="javascript">
    <!--
    function ConfirmWindow(strDialogMessage){
    var strMessage;
    var intResponse;
    intResponse = confirm(strDialogMessage);
    if (intResponse == 1) {
          
        // get the cute editor instance
        var editor1 = document.getElementById('<%=Editor1.ClientID%>');
       editor1.ExecCommand("New");

    return true;
    } else {
    return false;
    }
    }
    //-->
    </script>
     
     
     
     

    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

  •  07-14-2006, 9:25 AM 20982 in reply to 20974

    Re: Create Popup on Icon (image) Click

    Thank you for the response, but that solution doesn't work very well for me.  I am dynamically inserting controls into my page (form), so when I use <%= xx %> strings, .NET gives me errors saying that I can't dynamically add/change controls in a form that uses those string types.  Any ideas?  Error I am getting when trying to add one of my javascript controls called 'ClearFieldControl' is below.  I have many controls that I add dynamically to my pages to reduce my coding overhead.  Thanks for your help!
     

    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    Source Error:

    Line 299:        objLiteral.Text = objStringBuilder.ToString
    Line 300:        objLiteral.ID = "ClearFieldControl"
    Line 301:        objPageObject.Controls.Add(objLiteral)
    Line 302:        objLiteral = Nothing
    Line 303:        objStringBuilder = Nothing
  •  07-14-2006, 11:24 AM 20984 in reply to 20982

    Re: Create Popup on Icon (image) Click

    I think I found a solution for what I need.  You can continue to override the built-in New button as in my first example, but then just call your editor1.ExecCommand("New");  javascript.  I resolved my one issue above by just creating an additional argument to my javascript function for the Editor Client ID property.  Now this way it can be dynamic, I can continue to add my other controls dynamically, and the javascript function itself becomes dynamic.  This also means that you could potentially use the same javascript function for different buttons, links, or images on the form.
     
    The code is shown below.  I could easily make the javascript more diverse by putting in additional 'if' statements to test what button was pushed and respond to each one individually providing unique results.
     
    The following code snippets prompt the user to verify that they really want to clear the document.  If they do, then it will clear the document using the Cute ExecCommand javascript function.  If they don't want to clear it, the function exits and does nothing.
     
    The following Javascript goes into your html. 
      function ConfirmWindow(strDialogMessage,EID){ var strMessage; var intResponse; intResponse = confirm(strDialogMessage); if (intResponse == 1) { // get the cute editor instance var editor1 = document.getElementById(EID); editor1.ExecCommand("New"); return true; } else { return false; } }
     
    The following code goes in your vb code-behind page...

    CType(oCuteEditor.ToolControls("New").Control, System.Web.UI.WebControls.WebControl).Attributes.Add("onclick", "return ConfirmWindow(""Are you sure you want to clear this email??\nSelect 'OK' to delete or 'Cancel' to quit."",'" & oCuteEditor.ClientID & "');")

View as RSS news feed in XML