Sunday, March 10, 2013

Difference between WebPart & Visual Web Part in Sharepoint

Referred URL - http://sharepoint.stackexchange.com/questions/52075/difference-between-webpart-visual-web-part

 

Visual web part are born (afaik) from the SmartPart webpart project first seen on SharePoint 2007. The idea behind that project was to create a web part that could display any user control, so that programmer could work on ascx file as for any other web project instead to have to resort to programmatically create the controls via the CreateChildControl method.

The visual web part template introduced in Visual Studio 2010 just does this: it creates a simplified smartpart that displays the attached user control by adding it to the control collection in the CreateChildControl event. No more no less.

 

That said, beware that the visual web part does use a control, so it may cause issues in specific situation. First thing that comes to mind is that a visual web part is not supported in a sandbox solution (but you can use a modified template - see here or search for sandboxed visual web part in the visual studio gallery).

 

Waldek does a great job in is blog listing all the main differences: here is the link. What follows is just an extract of his notices, reposted to avoid link rooting. Also notice that as posted by almostSharepointMaster in his answer, you should also have a look at this page from Microsoftwhich also provides some samples.

Web Part / Visual Web Part comparision

No comments: