Wednesday, March 13, 2013

SharePoint : Accessing UserControl from inside a Web Part


I was working on a web part recently which could consume a user control in Visual Studio 2012 and SharePoint 2013 environment. So created a user control in CONTROLTEMPLATES folder and tried to access the user control using @Register tag with Src attribute specified automatically when the control is dragged onto the web part.
Surprisingly, I could not add the control onto the web part and Visual Studio gives compile errors. Then I thought even the user control code behind is precompiled into an assembly and the older dll version might have cached, I deleted the DLL from the GAC and tried to rebuild the project. Still the same.

I do not know why and how, but the solution seems to be that instead of referencing user control using Src attribute, specify the 'Assembly' attribute and 'Namespace' attributes correctly. Then we can add the user control to the web part as required

No comments:

Post a Comment