I have created one custom action. On clicking custom action, I am opening an application page as a modal dialog. The page will allow users to add the data of fields.
I have placed two buttons in the page, 1. Save , 2. Cancel. I want to add such a functionality that if Save is clicked then the form should be closed and the parent page should be refreshed. And if the cancel button is clicked then the page should be closed without refreshing.
I referred this MSDN Link to show the modal dialog.
My code for showing the page as modal dialog is:
var options = {
url: _spPageContextInfo.webAbsoluteUrl + '/_layouts/15/xx/Pages/Page.aspx',
tite: 'Edit Properties',
allowMaximize: false,
showClose: true,
width: 800,
height: 600,
};
SP.UI.ModalDialog.showModalDialog(options);
My code for closing the page without refreshing the page is:
protected void btnCancel_Click(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
Regex regEx = new Regex("[?&]IsDlg=1");
string currentUrl = Page.Request.RawUrl;
if (regEx.IsMatch(currentUrl))
{
context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");
context.Response.Flush();
context.Response.End();
}
}
When I click on the cancel button I am getting the following error in the console of the browser.
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
What am I missing?
Context
object. It isPage.Context
which is accessible directly.