Umbraco 4.5.2 Custom Create Control Fix in Custom Admin Trees

Umbraco Developer TutorialWhile 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.

Author

Jason Prothero

Jason leads the team at ProWorks Corporation, an Umbraco Platinum Partner specializing in complex Umbraco CMS builds, integrations, support, and upgrades. With 17+ years of Umbraco experience and an Umbraco MVP, he has led dozens of successful projects from versions as old as Umbraco 4 to the latest Long-Term Supported (LTS) releases. Jason is also leading the charge at ProWorks around AI and how to responsibly integrate AI into Umbraco and websites to create ROI and not simply as a novelty.

comments powered by Disqus
back to top