2

I'm planning to create a Visual Web Part. In the Visual Web Part's user control, I plan to embed an OOTB XSLTListViewWebPart, preferably through a declarative manner (in the .ascx). Has anyone done this before?

2

goto ascx, add this reference:

for sharepoint 2010:

<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

for sharepoint 2013

<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>    

now within the same aspx file below the refrences you can add:

<div id="customWebPartXSLT">

     <WebPartPages:XsltListViewWebPart runat="server" 

         ListUrl="Lists/myCustomList" 

         IsIncluded="True" 

         PageType="PAGE_NORMALVIEW" 

         Default="False" 

         ViewContentTypeId="0x" >

     </WebPartPages:XsltListViewWebPart>  

</div>

You need to change the list url to the name of your list, my example list is called myCustomList!

  • Thanks ali Sharepoint! I edited the code to remove the "<WebPartPages:WebPartZone ..> tag" because when the tag is there, the user control throws the error "Type 'Microsoft.SharePoint.WebPartPages.WebPartZone' does not have a public property named '{web part name}'." It is a known error discussed here. – Celbester Apr 25 '14 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.