Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Istvan Pszota 59 posts 191 karma points
    Jul 24, 2014 @ 15:54
    Istvan Pszota
    0

    How to do callback when using ClientTools.OpenModalWindow

    Hi Guys!

    I'm developing a CRUD back office application. One page opens a modal window using ClientTools.OpenModalWindow().

    I need to refresh the DataGrid once this modal window is closed. I realized the parameter 'onCloseCallback' but i can't figure it out why it is not called.

    Code in the aspx that contains the DataGrid

    protected void LinkButton1_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName=="Select")
            {
                var partner = dbc.GetPartnerByID(e.CommandArgument.ToString());
    
                ClientTools.OpenModalWindow("plugins/HWS/Editors/detailsPartner.aspx?partnerID="+e.CommandArgument.ToString(), partner.invoiceName, true, 800, 700, 0, 0, null,"refreshList");
            }
        }
    

    And have the following script on the same page:

     <script type="text/javascript">
            $(document).ready(function () {
                function refreshList() {
                    alert("refreshed");
    
                };
            });
    </script>
    

    I'm then closing the modal window with this:

    void saveBtn_Click(object sender, ImageClickEventArgs e)
        {
            ClientTools.CloseModalWindow().ShowSpeechBubble(Umbraco.Web.UI.SpeechBubbleIcon.Success, "message header", "message body");
        }
    

    The bubble shows up but the alert is not firing.

    What is the way to do this?

    Thanks in advance!

    Istvan

  • Istvan Pszota 59 posts 191 karma points
    Aug 11, 2014 @ 16:15
    Istvan Pszota
    0

    Nobody has ever done this before?

  • Tim Anderson 20 posts 83 karma points
    Aug 14, 2014 @ 18:08
    Tim Anderson
    0

    Hi Istvan,

    Looking at your code I don't see much wrong with what you are trying to do - in my current v6 installation we do something similar the only difference is that my JavaScript signature for the callback method looks like this:

    <script>
      function dialogCallback(data){
        /* Do something here... */
      }
    </script>
    

    It maybe that you need this parameter in your callback function and that is why it is not executing? The reason there is a parameter in there is because you can pass data back by passing a String to ClientTools.CloseModalWindow() like so

    void saveBtn_Click(object sender, ImageClickEventArgs e)
    {
        ClientTools.CloseModalWindow("Saved");
    }
    

    Therefore you could use that parameter to passback a serialized json object to your callback function with the state data or whatever you else you fancied doing with it.

    Off the top of my head that is the only thing that I can think of that is stopping it from working as intended.

  • Istvan Pszota 59 posts 191 karma points
    Aug 15, 2014 @ 16:13
    Istvan Pszota
    0

    Hi Tim!

    Will check this soon!

    Thanks, Istvan

  • Istvan Pszota 59 posts 191 karma points
    Aug 18, 2014 @ 17:02
    Istvan Pszota
    0

    Hi Tim!

    It still not working. I have placed

    <script>
      function dialogCallback(data){
        /* Do something here... */
      }
    </script>
    

    on the product list aspx. Also, amended the OpenModalWindow fuction to call the script.

    Revised the CloseModalWindow() to send the text.

    Added an alert function to your script, but it is still not fired.

    Do i need to reference any javascript file, or do i miss anything else?

    Thanks, Istvan

  • Tim Anderson 20 posts 83 karma points
    Aug 19, 2014 @ 13:25
    Tim Anderson
    100

    Hi Istvan

    I assume that your webform for your backoffice section page is inheriting from UmbracoEnsuredPage, in which case I am not referencing any additional Javascript files in my own pages. You may want to debug the page with the developer tools within your web browser to check that jQuery and the Umbraco script libraries have all loaded in properly.

    I've looked at one of the simplest pages where I use the callback and this is what JavaScript I have.

    function dialogCallback(data) {
        alert(data);
    }
    function myModalWindow(title,id,sid) {
        /* Constructs my query string */
        var qs = (id != null && id !== 'undefined' && id !== '') ? '?id=' + id : '?sid=' + sid;
        /* Construct my dialog url */
        var url = '/umbraco/Plugins/Dcc/Dialogs/MyDialogPage.aspx' + qs;
        /* call the umbraco open modal window library direct from javascript (as opposed to c# code using ClientTools) */
        UmbClientMgr.openModalWindow(url, title, true, 600, 550, 100, 100, '', dialogCallback);
    }
    

    Now when you close the modal window either by clicking by calling ClientTools.CloseModalWindow() from the MyDialogPage code behind - the callback function should execute.

    This all seems to work pretty well on my installation - you can see the only difference here is that I'm calling the modal window direct from JavaScript as opposed to using Umbraco's ClientTools object in C# - the reason being I wanted to set a few parameter values before I called the window (I have removed quite a bit of other code that's not relevant).

    If you are still having issues getting it to work - I would check that there are no other javascript errors preventing the code from running - debug your javascript using the developer tools of your browser.

    Kind regards,

    Tim

  • Istvan Pszota 59 posts 191 karma points
    Aug 29, 2014 @ 14:49
    Istvan Pszota
    0

    Hi!

    Sorry for not getting back any sooner! Just tested it and finally it works!

    Many thanks for your help on this!

    Istvan

Please Sign in or register to post replies

Write your reply to:

Draft