Wednesday, January 4, 2012

Using master page and layouts page in custom list view

I was struggling for couple of days now on how to make use of any master page in a layouts page which is used for a view of a custom list created using custom list schema.xml.

How to create a custom list definition is explained here (http://msdn.microsoft.com/en-us/library/ff728096.aspx)

I was able to create a custom list definition and added a custom list view page also in the schema.xml file itself. Here is how to add a custom list view using a layouts page (application page)

After adding a custom list schema, find the node "<Views>" and add a new "<View>" tag. You can just copy and paste the already existing "<View>" tag which has the BaseViewID="1" (this is the one which constitutes for the web page view. It is important that you should be copying the whole "<View>" node with all the internal elements like below.



To make use of the layouts page for the view, just change the "SetupPath" parameter to point to the corresponding layouts page without the "/" in front of the "layouts" folder (i.e., should be starting as "layouts/setup/settings.aspx") and change "Url" parameter to the name you want to see in the URL.

When I changed the "MasterPageFile" parameter to an application master page like below,

<%@ Page Language="C#" AutoEventWireup="true" 
                           MasterPageFile="~/_layouts/AppMasterPages/Simple.master" %>
 
the custom view gave me the below error

"The referenced file '/_layouts/AppMasterPages/Simple.master' is not allowed on this page"

If the "MasterPageFile" is change to "~masterurl/default.master", everything works well. If you are using a custom master page for the site you may make use of that by setting the "MasterPageFile" to "~masterurl/custom.master".

Happy coding.
Senthil S

No comments:

Post a Comment