Umbraco 4.5.2 Custom Create Control Fix in Custom Admin Trees
While working towards getting the Commerce for Umbraco project working in Umbraco 4.5.2 I encountered an issue that didn't appear to have an obvious fix. Luckily, a dive into the Umbraco source code provided an answer.
Commerce for Umbraco (C4U) has two custom creation dialogs for the Coupons and the Products. In Umbraco 4.0.x the dialog was closed after creation of the coupon/product and the tree refreshed by injecting the following javascript:
if (returnUrl == "") { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "refresh", "<script>\ntop.reloadCurrentNode();\ntop.closeModal();</script>"); } else { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "refresh", "<script type=\"text/javascript\">\ntop.reloadCurrentNode();\ntop.right.location.href = '" + returnUrl + "';\ntop.closeModal();</script>"); }
However, this didn't work in 4.5.2. I always thought this was a bit hacky, and although the code is probably actually doing the same thing the new way looks cleaner:
BasePage.Current.ClientTools .ChangeContentFrameUrl(returnUrl) .ChildNodeCreated() .CloseModalWindow();
You will need to use the following namespaces as well:
using umbraco.cms.helpers; using umbraco.BasePages;
So that is how you close and refresh a custom create dialog in your custom admin tree in Umbraco 4.5.2.
Feel free to ask questions in the comments.