Thursday 11 June 2015

Visual Webparts

Microsoft SharePoint 2010 introduced Visual Web Parts. Visual Web Parts are similar to user controls in that you can simply drag and drop items from the Toolbox onto your custom controls to create a Web Part UI. You also get the code-behind file where you implement the UI logic. Technically, the SharePoint 2010 Visual Web Part is an ASCX web user control that is hosted inside a standard Web Part.

In Microsoft Office SharePoint Server 2007, developers create Web Parts by deriving from the WebPart class. One of the challenges that users faced when designing a Web Part that has a complex user interface (UI) was the lack of drag-and-drop support. User  must write the code from scratch, in the CreateChildControls method, to create the layout design of the Web Part, which can be time consuming.
An alternative approach can save development time:

  1. Create a web user control by using Microsoft Visual Studio 2010 and design the control with the Visual Web Developer designer.
  2. Write the code-behind implementation of the user control.
  3. Create a Web Part to host the web user control.


A Visual Web Part is simply a classic Web Part that automatically loads the web user control with it. The advantage of this approach is that you can use Visual Web Developer to design the web user control. Traditional Web Parts differ from Visual Web Parts in several ways.

Differences in Web Part Properties :

Adding Web Part properties is cumbersome for Visual Web Parts as compared to traditional Web Parts. As you develop Web Parts, many times you will want to expose their properties so that users and administrators can supply the values for those properties.
Traditional Web Part
When you create a new Web Part (in this case SimpleWebPart), the SimpleWebPart.cs file is created for you. This is where you define the Web Part properties that inherit from the WebPart class.

Visual Web Developer provides drag-and-drop support without the need to write supporting code.


Visual web parts VS Standard web parts

1. A standard web part is an item-level template in Visual Studio. That means that you can only add it as an item to your project (an empty SharePoint project for example). A visual web part can be created as both item-level and project-level.
2. In the case of the visual web part, you can use a designer experience to drag and drop items on your canvas. In the case of the standard web part, you will have to manually type everything (using IntelliSense) .
3. A standard web part can be deployed as a Farm or Sandboxed solution. A visual web part will have to be deployed as a Farm solution.

http://www.randomizzzer.com/2011/06/explained-visual-web-parts-vs-standard-web-parts/

http://crmvoyager.net/2010/11/24/sharepoint-2010-web-parts-vs-visual-web-parts/

Web Parts vs. User Controls

One of the limitations of user control is that they cannot be shared across web applications but they can be created using a designer tool. On the other hand if you take custom controls, they can be shared across web applications, but there is no visual designer for creating custom controls through which we cannot drag and drop custom controls. By now, we understand that there is a need to have a solution that would combine the features of both the user controls and custom controls. The solution which will solve this issue is Web Parts.

Web Parts are prefabricated components that are basically targeted at easing the job of portal site / collaboration sites development. They are basically server-side controls that run inside the context of special pages (known as Web Part pages) within an ASP.NET application or a WSS (Windows SharePoint Services) site. Web parts combine the flexibility of user controls and custom controls. Developers can drag completed Web Parts from Web Part galleries and drop them into Web Part zones. It can also be said that web parts add more value over other types of ASP.NET controls in that they add extra dimensions of user customization and personalization.

http://mr-ponna.com/Question/357/What-is-the-difference-between-a-web-part-and-a-user-control-/

http://sharepointdeveloper1987.blogspot.com/2012/07/basic-difference-between-visual-webpart.html



User Control VS Web Part
User controls are based on Microsoft ASP.NET, and most developers are familiar with developing user controls. This improves productivity.
User controls can be used with ASP.NET -based solutions. If you decide later to convert a project containing a user control to an ASP.NET -based solution, you should be able to use the control without making any changes.
The Visual Web Developer designer provides support for designing the UI by using drag-and-drop operations that gives the control a consistent look-and-feel, which results in faster development.
User controls must be compiled before use, which adds to the time it takes to load the control.

In general, developers are not familiar with creating child controls by writing the code from scratch.
Web Parts can be used in ASP.NET -based solutions only when the solution uses Web Parts pages.
The controls in Web Parts must be added by using code.
Web Parts are pre-compiled and ready for use as soon as you need them.

In SharePoint 2010, Visual Web Parts are similar to user controls.

SharePoint 2010 Visual Web Part is an ASCX web user control that is hosted inside a standard Web Part.

http://microsoftechies.com/2013/01/10/sharepoint-difference-between-user-control-or-web-part/

https://msdn.microsoft.com/en-us/library/hh857549(v=office.14).aspx

No comments: