Esempio n. 1
0
    /// <summary>
    /// Handles the OnAfterSave event of the EditForm control.
    /// </summary>
    protected void EditForm_OnAfterSave(object sender, EventArgs ea)
    {
        String saveScript = AfterSaveScript;

        if (saveScript != String.Empty)
        {
            ScriptHelper.RegisterClientScriptBlock(this, typeof(String), "aftersavescript", ScriptHelper.GetScript(saveScript));
        }
        else
        {
            if (!String.IsNullOrEmpty(RedirectURL))
            {
                URLHelper.Redirect(RedirectURL);
            }

            if (newItem)
            {
                String url = RedirectURL;
                if (String.IsNullOrEmpty(RedirectURL))
                {
                    // Find element representing new object
                    UIElementInfo uiPar = UIElementInfoProvider.GetUIElementInfo(UIContext.UIElement.ElementParentID);
                    if (uiPar != null)
                    {
                        // Append parameters
                        url = UIContextHelper.GetElementUrl(uiPar.GetEditElement(), UIContext);
                        url = URLHelper.AppendQuery(url, "objectid=" + EditForm.EditedObject.Generalized.ObjectID + "&saved=1");

                        // Ensure that the redirected edit page will behave as a top dialog page (hide breadcrumbs, uses dialog page title...)
                        url = URLHelper.RemoveParameterFromUrl(url, "rootelementid");

                        // Append action edit parameter
                        url = URLHelper.AddParameterToUrl(url, "action", "edit");
                    }
                }

                // Ensure hash for dialog mode
                url = UIContextHelper.AppendDialogHash(UIContext, url);

                EditForm.RedirectUrlAfterSave = url;
            }
        }

        // Raise the javascript return handler function
        RaiseReturnHandler();

        if (itemChanged)
        {
            String refreshWopener = String.Empty;

            // Refresh opener for dialog page.
            if (IsDialog)
            {
                refreshWopener = "if(wopener!=null) {if (wopener.Refresh != null) {wopener.Refresh()} else if (wopener.RefreshPage != null) wopener.RefreshPage();}";
            }

            ScriptHelper.RegisterClientScriptBlock(Page, typeof(String), "RefreshParent", ScriptHelper.GetScript(refreshWopener + "if (parent.refreshPage) {parent.refreshPage()} else parent.location = parent.location;"));
        }
    }
    /// <summary>
    /// Handles the OnAfterSave event of the EditForm control.
    /// </summary>
    protected void EditForm_OnAfterSave(object sender, EventArgs ea)
    {
        String saveScript = AfterSaveScript;

        if (saveScript != String.Empty)
        {
            ScriptHelper.RegisterClientScriptBlock(this, typeof(String), "aftersavescript", ScriptHelper.GetScript(saveScript));
        }
        else
        {
            if (!String.IsNullOrEmpty(RedirectURL))
            {
                EditForm.RedirectUrlAfterSave = RedirectURL;
            }
            // If there is some redirect URL already set in the UI form, do not override this value with the URL taken
            // from the UI element, or with the generated one.
            // Existing value can only be set from the extender and therefore has higher priority.
            else if (newItem && String.IsNullOrEmpty(EditForm.RedirectUrlAfterSave))
            {
                // Find element representing new object
                UIElementInfo uiPar = UIElementInfoProvider.GetUIElementInfo(UIContext.UIElement.ElementParentID);
                if (uiPar != null)
                {
                    // Append parameters
                    string url = UIContextHelper.GetElementUrl(uiPar.GetEditElement(), UIContext);
                    url = URLHelper.AppendQuery(url, $"objectid={EditForm.EditedObject.Generalized.ObjectID}&saved=1");

                    // Ensure that the redirected edit page will behave as a top dialog page (hide breadcrumbs, uses dialog page title...)
                    url = URLHelper.RemoveParameterFromUrl(url, "rootelementid");

                    // Ensure hash for dialog mode
                    url = UIContextHelper.AppendDialogHash(UIContext, url);
                    EditForm.RedirectUrlAfterSave = url;
                }
            }
        }

        // Raise the javascript return handler function
        RaiseReturnHandler();

        if (itemChanged)
        {
            String refreshWopener = String.Empty;

            // Refresh opener for dialog page.
            if (IsDialog)
            {
                refreshWopener = @"
if(wopener) {
    if (wopener.Refresh) { 
        wopener.Refresh()
    } else if (wopener.RefreshPage) {
        wopener.RefreshPage();
    }
    else {
        wopener.location.reload(true);
    }
} else ";
            }

            refreshWopener += @"
if (parent.refreshPage) { 
    parent.refreshPage()
} else {
    parent.location.reload(true);
}
";

            ScriptHelper.RegisterClientScriptBlock(Page, typeof(String), "RefreshParent", ScriptHelper.GetScript(refreshWopener));
        }
    }