I added few XsltListViewWebPart web parts programatically on a page using below code:
Unable to get property 'IsClientRendering' of undefined or null reference.
This didn't give me any clue. However, after some research I found that in the code above we need to call SPLimitedWebPartManager.SaveChanges method to get rid of this issue. Here is the updated code:
public static void AddXsltListViewWebPartToPage(SPLimitedWebPartManager wpm, string listName,
string viewName, string zoneId, int zoneIndex, bool isServerRender, SPWeb web)
{
SPList l = web.Lists[listName];
XsltListViewWebPart xsltWp = new XsltListViewWebPart();
xsltWp.ListName = l.ID.ToString("B").ToUpper();
xsltWp.ViewGuid = l.Views[viewName].ID.ToString("B").ToUpper();
wpm.AddWebPart(xsltWp, zoneId, zoneIndex);
}
The web parts were added successfully on the page. New items were also added to the lists properly. However, the ECB menu was not appearing consistently on clicking of a link field. I debugged the javascript code and found this error:Unable to get property 'IsClientRendering' of undefined or null reference.
This didn't give me any clue. However, after some research I found that in the code above we need to call SPLimitedWebPartManager.SaveChanges method to get rid of this issue. Here is the updated code:
public static void AddXsltListViewWebPartToPage(SPLimitedWebPartManager wpm, string listName,
string viewName, string zoneId, int zoneIndex, bool isServerRender, SPWeb web)
{
SPList l = web.Lists[listName];
XsltListViewWebPart xsltWp = new XsltListViewWebPart();
xsltWp.ListName = l.ID.ToString("B").ToUpper();
xsltWp.ViewGuid = l.Views[viewName].ID.ToString("B").ToUpper();
wpm.AddWebPart(xsltWp, zoneId, zoneIndex);
wpm.SaveChanges(xsltWp);
}
Reference