Dataview web parts in your master page cause errors on subsites

If you’ve had this problem, then two things to make you feel better:

  1. The solution is very easy
  2. The cause of the problem is stupid stupid stupid. You can bang your head against the keyboard, there’s no way you could have known.

This post, meanders a bit, so if you want the solution, jump to the bottom.

Still here? Sucker.

So, what are the prerequisites to causing this problem:

  • you have a dataview web part inserted into a master page;
  • the dataview refers to data in a list; and
  • the list is scoped at the root web of the site collection.

I think that’s it.

Symptoms

The web part will display correctly anywhere in your root web, but nowhere else. I’m calling it a “web” here because it maps to how Sharepoint’s API. If it helps for you to think about it as a single “Site” in WSS2.0 fashion, go nuts. When you visit subsites, you see the following error:

“Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.”

How helpful, especially if you’re an administrator or developer. As if they’d have a magic wand to fix the problem. The error might as well say:

“You’re screwed. Unless you’re a clever developer, give up, swear at Sharepoint and call tech support. Not many people at your company are going to be able to help you.”

Which is silly, because once we come to the cause, the error is completely within the realms of detection. To the developer who wrote that line of code… 10 minutes on the naughty step.

The problem is seemingly unresolveable. If you try to add the dataview directly to a page in a subsite, it works fine, but master page? Sharepoint tells you to go whistle.

Cause

The cause? Sharepoint doesn’t know which “web” the list comes from.

The Dataview web part can take parameters, including, parameters which tell pages where to find a list. In Sharepoint Designer, when you edit a master page, it fails to insert a parameter telling pages the list lives in the root.

Bad Sharepoint Designer! Bad!

The problem compounded because taking a dataview created on a subsite and dumping the code into the masterpage doesn’t work either (which makes it very tricky to solve).

To figure this out, I took the following steps in Sharepoint Designer:

  • Created a dataview in the master page (worked at top level and nowhere else)
  • Created the dataview with the exact same settings on a page in a subsite
  • Copied the code snippets into a text-editor and compared them side-by-side

A side-by-side comparison revealed several things…

Web part parameters in the master

Web part parameters in a page

First, the datasource control (a child of the dataview web part) is referred to with a different namespace in the master page than in the page itself. This is why you can’t copy dataview code from a regular page into a master page. Maybe there’s a good reason for having done this, but I think the masterpage programmer forgot to speak to the regular page programmer. However, that isn’t the root cause, but something to be aware of.

Second, THERE’S ANOTHER PARAMETER. OMG!!! Froth, swear, stomp, swear, slam your keyboard. Feel better?

Knowing a parameter exists and knowing the syntax are two different things. Before finding the actual code, I was pretty confident the problem was down to subsites not knowing where the list was.

The worst thing is that the url of the web is actually part of the dataview web part, down at the very bottom of the code. Why doesn’t this flow through to the datasource? Naughty step!

Web part parameters

Solution

It’s simple enough to copy the parameter from the subsite dataview into the masterpage dataview.

<WebPartPages:DataFormParameter Name=”WebURL” ParameterKey=”WebURL” PropertyName=”ParameterValues” DefaultValue=”/”/>

I don’t believe the approach is necessary if you’re referring to a list in a subsite (the parameter should be inserted automatically).

Hope that helps!

24 responses to “Dataview web parts in your master page cause errors on subsites”
  1. Dave says:

    Thank you very much four your solution! I already lost some hours while searching the cause for this problem… Now it’s fixed! Thanks a lot!

  2. Nag says:

    Excellent Article. I wasted couple of hours in fidning out the cause for this behaviour. Then found your article on net. It fixed the problem. Thank you very much!

  3. Mary Lou says:

    I have a dataview web part that was a part of the Help Desk Request Template from Microsoft. The Average Time Resolved web part worked fine as delivered but when I made changes to the list it references, the Service Requests list, it broke the connection to the data. I have looked at the code in SharePoint Designer and made sure that the GUID for the ListID is the correct GUID for my site. I have checked the <ParameterBinding DefaultValue = {the GUID fro my list}, I have changed the GUID in the <WebPartPages:DataFormWebPart ListName and in the <SharePoint:SPDataSource DefaultValue. It still does not display and I still get the error message “Unable to display.. “. by the way I like you error message much better. Any other suggestions? Thanks

  4. admin says:

    Tricky, without having my hands on the keyboard, but I’ll do my best.

    What I always do when stuck is to go back to the very beginning, i.e. can you get the Average Time Resolved part to work on any page?

    Then, can you get a vanilla data view to work with the service requests list.

    Then, look at the underlying parameters and do a side by side comparison.

    Also check to see whether it works in the web hosting the Service Requests list (and if so, does it fail in other webs).

    If you changed the type of column, that might also cause pain (i.e. change a text column to a choice column).

    If you haven’t already done those things, I hope those ideas help.

  5. Ehab Zaghmout says:

    Thanks,
    This problem is straightforward, i have already solved it long time ago, but the problem i’m facing is that i have a 20 replicated sites, all are using the same masterpage, and the master page includes a section for displaying news for each site, i have created a javascript function to get the name of the site, can i pass the value of this function to the subview as shown below??
    i tried to add the name of the site manually inside the DefaultValue parameter, and it worked, for example:
    WebPartPages:DataFormParameter Name=”WebURL” ParameterKey=”WebURL” PropertyName=”ParameterValues” DefaultValue=”/IT/”

    but i need to pass the value dynamically,as shown below!!!!!
    WebPartPages:DataFormParameter Name=”WebURL” ParameterKey=”WebURL” PropertyName=”ParameterValues” DefaultValue=”MyJavaScriptFunctionValue”

    Thanks and Regards,

  6. admin says:

    Sorry Ehab, but unfortunately that approach won’t work. The problem you will face is the is 100% server-side (so Javascript cannot help you).

    What you might consider is the following

    1 – Create a web part which inherits from the DataView web part
    2 – Override the OnPreRender event (or constructor) to set the value of the url. For example

    somefunction()
    {
    this.weburl = this.site.rootweb.url;
    }

    Then drop that webpart into your masterpage instead of the regular dataview. The code above is almost certainly wrong as I don’t have my Sharepoint reference handy but should get you started.

    An alternative way of doing this is writing a separate web part which you deploy on the master page which interacts with the web part manager, finds the dataform and sets its weburl value for it, which would be cleaner.

    Sorry, can’t think of a better way of doing this.

  7. Nandita says:

    Thank you so much; Saved me lot of trouble.

  8. hina says:

    Hello,

    After implementing the solution , provided in the above post, it is not giving me ‘unable to display webpart error’ on subsite page.

    But now i am getting the error ‘Object reference not set to an instance of object’, again same thing is working fine with root site page.

    Now if i uncheck ‘Sharepoint list toolbar’ option by right click on dataform webpart it works fine on subsite page also, but i need list toolbar.

    Please find attached file for the error message.

    Any help on this will be appriciated.

  9. Lost says:

    Hi,

    “But now i am getting the error ‘Object reference not set to an instance of object’, again same thing is working fine with root site page.

    Now if i uncheck ‘Sharepoint list toolbar’ option by right click on dataform webpart it works fine on subsite page also, but i need list toolbar.

    Please find attached file for the error message.

    i’m facing the same issue, did anyone found a solution???

  10. admin says:

    I must confess I haven’t run into the error you mention. I need to get my dev environment up and running again and will have a look.

  11. Lost says:

    More informaiton ,

    What i’m trying to do is add a dataview webpart in the Default.aspx of the subsite to read a Document Library list from the root site from a subsite.

    It works fine without a toolbar, as soon as i add a toolbar it says the following,

    in sharepoint designer Error Rendering COntrol …….

    when running the website

    [NullReferenceException: Object reference not set to an instance of an object.]
    Microsoft.SharePoint.WebControls.NewMenu.CreateChildControls() +69

    Any idea what could be causing this problem.

    Thanks for the help.

  12. Sharepoint Newbie says:

    this looks exactly like my problem, but being a computer-savvy Sharepoint-newbie non-developer type, I don’t understand the solution.

    Would someone kindly post a few pointers?

    For example, where can I find the “subsite dataview” and the “master dataview”. And, is it literally a copy-and-paste-once or is it some kind of string replace?

    Some background:
    I spent pretty substantial time creating a website based on Microsoft-provided templates that are being hosted on an outsourced Sharepoint hosting platform. I am using SPD to backup and restore to my local site. All this was fine, except the restored website doesn’t work and specifically in the Microsoft-developed areas of the site, where it is simply displaying context-sensitive vanilla webparts: “Shared Documents”, “Discussion” items, “Tasks”, etc.

    thanks in advance for your help.

  13. Bill says:

    Sweet. This is exactly what I’m looking for as well. However, I’m a bit confused about the solution. Please forgive the ignorant question, but here it goes:

    Where specifically is the masterpage dataview? I’m assuming it’s either the root master page for the site, or the “all items” page for the list. I cannot find “parameterbindings” on either page, however.

    I’m attempting to create a datasource of the parent sites calendar on each of the sub-sites default page. Don’t care too much about allowing people to create list items directly from the datasource web part, but I would like it to take on a standard “calendar view.”

  14. [...] Neil Richardshas apparently discovered the cause of this issue, and has isolated a simple solution. Unfortunately, I have no idea what he is talking about. It’s simple enough to copy the parameter from the subsite dataview into the masterpage dataview. <WebPartPages:DataFormParameter Name=”WebURL” ParameterKey=”WebURL” PropertyName=”ParameterValues” DefaultValue=”/”/> [...]

  15. [...] The answer is just to add this line four times per this excellent blog entry http://www.neilrichards.net/blog/?p=42 [...]

  16. Johnny R says:

    The solution is vague. What exactly do I need to do? I would appreciate some guidance.

  17. [...] Knowledge with Neil » Blog Archive » Dataview web parts in your master page cause errors on subsit… (tags: SharePoint) [...]

  18. Kungfu MOSS says:

    This is a great post, Neil. Just had this worked on my Dev machine. However, could not duplicate it on the pre-product environment, is there any Sharepoint configuration notes we need to take for this solution? I double checked all the possible issues like GUID, check in/out and version controls, all are fine, it just showed on the first root level pages but not on subsite level…. Any comments?

  19. admin says:

    Sorry Johnny I think it’s reasonably detailed. By now though you’ve probably given up or figured it out.

  20. admin says:

    Couldn’t say for certain. What’s the error message (detailed, not the useless Sharepoint “Unexpected Error”)

  21. AY says:

    Hi Neil,

    This post is a few years old and I am hoping that you reply to me on this. The problem I am facing is that the dataview webpart of a particular library is showing this problem and that also for one user only (Guess who? My Boss). For others its working fine.

    I have tried to import new dataview webpart (from the same form library) to other pages as well. But same problem: not working for one user only, and showing the stated problem.

    I am hoping you will help me with this. Thanks!

  22. admin says:

    If its happening to one user only then they probably don’t have access to the target library. Try giving them a direct link to the target list. If they can’t see it, that’s the source of your problem (SharePoint wont show you data that you don’t have access to).

  23. Dan says:

    Hi,

    I know this is old news now, but I am getting the rendering error you describe. I have a list (contacts) on a subsite that is not the root web for the site collection within Sharepoint 2007. Call it MyTeam. Underneath MyTeam I have a large number of subsites for clients, call them ClientA, ClientB etc.

    I have created page within the ClientA subsite, with a dataview webpart that connects to the Contacts list on MyTeam, and filters against the company name field to ensure only relevant contacts are displayed. This works fine, but I want the list to a) look the same in the parent and child subwebs, and b) be able to edit/add etc. So I try to turn on Sharepoint LIst View and get the error you describe.

    I have gone through the code as best I can (I am a project manager, not a coder) and it seems that it has the relevant parameters that you describe, but still doesn’t work. Here is my webpart code, and help you can provide would be GREATLY appreciated:

    @Title,Title;@LastNamePhonetic,Last Name Phonetic;@FirstName,First Name;@FirstNamePhonetic,First Name Phonetic;@FullName,Full Name;@EMail,E-Mail;@Company,Company;@CompanyPhonetic,Company Phonetic;@JobTitle,Job Title;@WorkPhone,Business Phone;@HomePhone,Home Phone;@CellPhone,Mobile Phone;@WorkFax,Fax Number;@WorkAddress,Address;@WorkCity,City;@WorkState,State/Province;@WorkZip,ZIP/Postal Code;@WorkCountry,Country/Region;@WebPage,Web Page;@Comments,Comments;@ContentType,Content Type;@ID,ID;@Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;


    0

    Table

    Title
    City

    ms-alternating

    |

    |

    View:
    &nbsp;

  24. admin says:

    I’m afraid your code didn’t come through so its not straightforward to know what the problem is. If you’re hitting data from other sites and you’ve setup the datasource using SharePoint designer, you really shouldn’t have a problem. My post is a bit different in that it’s for a masterpage where the dataview follows you around but it omits the WebId.

    In yours, without a WebId you wouldn’t even see data showing up in SharePoint designer.

Leave a Reply