Thursday 25 April 2013

How to close a custom modal dialogue (application page) in SharePoint

We created an application page in SharePoint, which opens up as a modal dialogue box on one of the Button click. Functionality wise, page was working fine and we didn't face any issue with it until we thought of having a close button on application page.

Till now the only way to close the page was by clicking on "X" button present in extreme right top corner.

Here is how we achieved this:

1. Created a cancel button, as shown below, in aspx page:


2. On button click event, add below lines:
protected void btnCancel_Click(object sender, EventArgs e)
{
     Context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");
     Context.Response.Flush();
     Context.Response.End();
}

No comments:

Post a Comment