Sharepoint 2010 – Create custom modal dialog using Visual studio 2010
06/07/2011 • Admin
Category: SharePoint 2010
Detailed steps to create a custom modal dialog page and show it when a ribbon button is clicked in a document library.
User Case -
1. User clicks on Ribbion button “About” in the document library.
2. About button the displays the custom dialog page and passes the current library name.
3. The dialog page then parses the url parameter, Library name in our case and display the description field as text in the dialog page.
Results -
Ribbon Button
About Dialog -
Steps –
1. Create a empty project “custommodaldialog”.
2. Deploy it as a Farm solution.
3. Right click on the feature and click “Add feature”.
4. Next right click on project and add a new item and select an application page “MyCustomDialogPage.aspx”. This will be out cutsom dialog page.
5. Open the MyCustomDialogPage.aspx page and add a lablel “AboutText” in PlaceHolderMain.
6. Next, write the below code in the applictaion page to display the About text for a library.
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace CustomModalDialog.Layouts.CustomModalDialog
{
public partial class MyCustomDialogPage : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
SPWeb web = SPContext.Current.Web;
if (Request.QueryString["sourcelibrary"] != null)
{
String CurrentListName = Request.QueryString["sourcelibrary"].ToString();
SPList _currentList = web.Lists[CurrentListName];
AboutText.Text = string.Format(“
About This Library
{0}”,_currentList.Description);
}
}
}
}
You Project should look like -
7. Next we will create an empty element to display our custom ribbon button “About” which when clicked will open up
our above created custom dialog page. See Part 2 >>







Recent Forum Posts
Linq to Sharepointby RS on May 18, 2012
comments on the codeby spbsmile on May 18, 2012
connection(add) EditControlBlock and my programby spbsmile on May 18, 2012
Custom master pages used in multiple SharePoint 2010 sitesby ubersteve on May 18, 2012
upload file and click on button but cant upload file into list by using below codeby santhoshreddy on May 18, 2012