So can you put Web Part Zones in Master Pages, or what?

A customer wants to put a web part zone below the quick nav in their SharePoint site – not an unusual request. Naturally, I cracked open SharePoint Designer, and tried adding a web part zone – and this is what I got:

I tried to understand why this would be the case, but quite simple, couldn’t. Naturally, I then referred to the documentation (!) on MSDN. It had mentioned this at the bottom of the page.

You cannot add Web Parts in zones to a master page. You can add static Web Parts (parts outside of a zone) to a master page, but you cannot add dynamic Web Parts to master pages.

Okay, that seems clear enough – I get why you could add static web parts to a master page, but not dynamic – but what about the web part zones themselves?

You can add zones to master pages and later add Web Parts to the zone in the browser, but the Web Parts are associated with the content page.

Yup, that seems fair enough. I get that in theory. So why in practice does SharePoint Designer say I can’t?

I began looking around to see if others had tried this – and found interesting contradictions. Mirjam says you can’t – but does point out that you can override the standard quick nav in your page layout, and put a web part zone into that. Microsoft SharePoint Step by Step seems to say the same thing. Yet ASP.NET would support this just fine, and as noted the MSDN docs say it should work.

Okay, one thing left to do – actually try it. SharePoint Designer won’t let me add the web part zone by ‘drag and drop’, but I can code one by hand:

And it renders in SharePoint Designer:

But when you try and use the page:

Well, I ain’t going to argue with a parser error – it looks like you really can’t do this, despite the MSDN docs.

6 thoughts on “So can you put Web Part Zones in Master Pages, or what?”

  1. Hi,

    I have been a regular follower of ur blog site.

    I want to add a web-part zone in master page, i read ur post and it seems i can’t do it…

    basically, i wanted to add a common announcement ticker to the master page that will fetch data from a list in the top-level site collection and rotate it…

    is there another way, how can i use a user control to fetch data from the list using the SP Object model…

    any clues…

  2. Mehul to talk to a list via a custom control you need to add an assembly reference to Microsoft.Sharepoint in the web.config file of the WebPage that the custom control belongs to.

    To back it up a little, you will need to create a new ASP.NET, or ASP.NET AJAX Enabled website, add a user control to that website, and in the code begind add a using reference for Microsoft.Sharepont. This will alllow you to access the object model, and then you can write the code to talk to the list you want. Put the control and its code behind in the directory mentioned below, and you can access it from the SmartPart mentioned below.

    You will also need to use a smartpart web part that will reference the user control.

    You can find one at http://smartpart.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=10697

    For this to work you need to put a UserControls folder in the virtual directory for your site. Should be somewhere like this

    C:\inetpub\wwwroot\virtualdirectories\”YourPortNumber”\UserControls

  3. Hi
    You cant Put dynamic webpart in SharePoint Master Pages because Static Web Parts Allowed.
    If You Want to have to do that you can do it By creating a page layout
    and you can customize it.
    to create page layout in share point :

    1. go to site actions —-> site setting —-> modify all site setting—-> Galleries—–>site

    content type— > Create

    2. Enter the name Of the Page Layout

    3.from parent content type select Publishing Content type

    4. select page

    5.in Existing group select page layout content type then ok

    6. go to SP designer select the page open it and modify it as you like the right click it
    check in the approve the create pages from it

  4. Here’s how you could add a WebPartZone/WebPart to a page using designer.

    Add a place holder in the master page.
    eg.

    Now add a asp:content control and give “ContentPlaceHolderId” same as the “ContentPlaceHolder” in master page. Inside this add a WebPartZone and add your WebPart within the Zone.
    eg.

  5. Hi!

    I have succesfully placed a custom webpart(with a treeview) in my custom master page and everything seems to be working fine…recently we came through an issue that the custom webpart in master page is not working in layout pages(when i click on a link in the treeview, the page is not navigating to the corresponding link and the webpart is becoming invisble) ……can you suggest a solution for this?

    Thanks,
    Sudheer.

Comments are closed.