Web Part or Web Form Control on this Page cannot be displayed or imported. while adding a custom webpart in SharePoint 2013

Hi All,

I was developing a custom SharePoint web part for SharePoint 2013 using VS 2013, after i deployed the wsp and when i was adding the web part, i was getting the following error message:

Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe.


This is a common SharePoint error when you try to load custom user controls (or Visual Web Parts) into a SharePoint page. 

Any custom control has to be added as a safe control in SharePoint, before VS 2013 we used to add entries in the site web.config or code to add the safe control either programmatically to the site. but you do not need to do this in Visual Studio 2013 since it has a tool to add safe controls through a UI by specifying the namespace and the type and your control will be loaded with no issues or errors.

In VS 2013, follow these steps:

1) Double click on the package item.
2) Under Advanced tab.
3) If the custom control exists in an assembly so when you add the assembly that contains your user control click on add safe control button and specify your assembly & type for their user control.
Or even if the custom control is contained in a project within your solution, so when you add the project output in the package explorer UI, you can still add the user control as a safe control by specifying the namespace and type fields.

4) Safe the changes, build and deploy.
5) Refresh the SharePoint page.
6) Add your custom web part and you will not get the error message.

Enjoy!


Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>