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.
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
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.
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.
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
And have the following script on the same page:
I'm then closing the modal window with this:
The bubble shows up but the alert is not firing.
What is the way to do this?
Thanks in advance!
Istvan
Nobody has ever done this before?
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:
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
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.
Hi Tim!
Will check this soon!
Thanks, Istvan
Hi Tim!
It still not working. I have placed
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
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.
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
Hi!
Sorry for not getting back any sooner! Just tested it and finally it works!
Many thanks for your help on this!
Istvan
is working on a reply...