Close SharePoint modal dialog using visual studio 2010 in SharePoint 2010

InfoPath alternatives for form designing SharePoint

In this post we will discuss how to close a SharePoint modal dialog box using Visual Studio 2010 in SharePoint 2010.

Also you can check out:

– Check if list already exists or not using sharepoint 2013 client object model autohosted apps

– Create an event handler to prevent items from deleting item from SharePoint list using Visual Studio 2010

– Custom timer job sharepoint 2010

1. First we create the application page using visual studio 2010 and map the folder with SharePoint layouts folder and I give the name of that application page WFView.aspx. See in fig

 Close SharePoint modal dialog using visual studio 2010 in SharePoint 2010
Close SharePoint modal dialog using visual studio 2010 in SharePoint 2010

2. Now in this page I added two buttons. Replace the code in place of <asp:Content ID= “Main”

<asp:Content ID=”Main” ContentPlaceHolderID=”PlaceHolderMain” runat=”server”>

<h1>Custom Content Type View Page to approve the workflow activities</h1>

<asp:Button ID=”btnApprove” runat=”server” Text=”Approve” onclick=”btnApprove_Click”/>
<asp:Button ID=”btnReject” runat=”server” Text=”Reject” onclick=”btnReject_Click”/>

</asp:Content>

3. Now open the code behind code and add the following method for buttons

protected void btnApprove_Click(object sender, EventArgs e)
{
<!— this is code for closing the model dialog after event is fire –>
Context.Response.Write(“<script type=’text/javascript’>window.frameElement.commitPopup();</script>”);
Context.Response.Flush();
Context.Response.End();
}

protected void btnReject_Click(object sender, EventArgs e)
{
<!— this is code for closing the model dialog after event is fire –>
Context.Response.Write(“<script type=’text/javascript’>window.frameElement.commitPopup();</script>”);
Context.Response.Flush();
Context.Response.End();
}

4. Now save and deploy.

5. Now when you open the page as model dialog than you able to see your page with two buttons. See in fig.

 Close SharePoint modal dialog using visual studio 2010 in SharePoint 2016
Close SharePoint modal dialog using visual studio 2010 in SharePoint 2016

6. Now when you click on Approve or Reject button the form will be close.

Note – If you are not using that code then when you click on button, your event is fire but the page will be not close.

Similar SharePoint 2013 Tutorials


About Navneet Singh

I am Navneet Singh, Working at C3it software solutions pvt. ltd. in Pune. My core skills are SharePoint 2013, Office 365, SharePoint 2010, SharePoint Designer, SharePoint Designer Workflow, Nintex Workflow, Infopath, Webpart, CSOM/SSOM, Power-shell, C#, ASP.NET and SQL Server.

View all posts by Navneet Singh →

Leave a Reply