Now that you’ve got a good understanding of how a SharePoint page is constructed and what factors are important in determining the overall look and feel of a site, let’s move on to look at how you can add additional functionality to a page.
You’ve seen how you can use tools such as InfoPath forms services to customize input forms. But what if you want to add functionality that goes beyond the capabilities of InfoPath? Let’s look at a few options—the first is to create a custom web part. Two types of web parts can be used within SharePoint: legacy web parts that are derived from the Microsoft. SharePoint. WebPartPages. WebPart base class, and standard ASP.NET web parts that are derived from the System. Web. UI. WebControl. Webparts. WebPart base class. The recommended approach for creating new web parts is to use the ASP.NET model.
Web Part Infrastructure
Before we delve into a discussion on how to create web parts for use with SharePoint, let’s recap how the ASP.NET web part infrastructure works and what it does. A web part is a server control that exposes functionality that allows it to be configured or personalized by nontechnical users. In a sense, web parts are like building blocks: we can choose the web parts that we need to build something and stick them on the page wherever we want them. To provide this functionality, the web part infrastructure has a few additional elements that should be included on a page. One of the first is the WebPartManager control, which is used to manage the configuration information for each web part on a page. As well as a WebPartManager, to allow designers some control over where web parts can be placed, the web part infrastructure makes use of WebPartZone controls that represent zones within a page where web parts can be added.
The SharePoint platform defines custom WebPartManager and WebPartZone controls that are derived from their ASP.NET counterparts. This allows web part settings to be persisted and controlled in a way that better suits the SharePoint page rendering mechanism. For example, one of the new features in SharePoint 2010 is the ability to version web part configuration along with other elements on a page. This functionality makes use of the custom SPWebPartManager class. Earlier we looked at the default v4.master page that provides the basis for rendering all SharePoint pages. It’s worthwhile to note that this master page contains a SPWebPartManager control, so all pages that are derived from this master page can make use of web parts.
Web Part Security
Web parts are a bit like building blocks; users can build whatever they like with them. However, left unchecked, users can potentially build resource-hogging monstrosities that can kill a site for all other users. To prevent this and to give administrators some control over the web parts that can be included on a page, SharePoint requires that all controls be registered as safe before they are allowed to be included. Safe controls are specified using a series of SafeControl elements within the site’s web.config file. In addition to requiring controls to be explicitly specified as safe for a given site, web parts can also make use of code access security to restrict the actions of web part code even more.
Creating a Web Part
To demonstrate how web parts can be created and used within a SharePoint page, let’s work through an example. We’ll create a simple web part that accepts two property values: a color and the name of a SharePoint list. The web part will display a list of items in the list using the selected colors. Although this is a trivial example, it will illustrate the key elements that are used when building more useful web parts.
We’re querying the configured list and creating an unordered list of the title of the top 50 items. Notice that the attributes that are applied to the TextColor and ListName properties. For the property to be visible in the Property Editor pane, WebBrowsable must be set to true.
Improving the Property Editing Experience: Editor Parts
For our sample web part, we’ve used a text box to allow users to enter the name of a list. While this works as we expected, it’s not exactly an ideal interface. A better approach would be to show a drop-down list of available lists and allow the user to select one. To implement this functionality, we’ll use an editor part. Editor parts are also server controls and work in a similar fashion to web parts. However, editor parts are rendered within the Property Editor pane, and their primary function is to enhance the design-time experience for users.
To add a new editor part, take the following steps:
Visual Web Parts
In our examples so far, we’ve adopted the standard ASP.NET approach to building web parts. Because a web part is a server control, the user interface needs to be manually constructed. In our simple examples, this didn’t cause too much trouble; however, as the user interface gets more complicated, this approach becomes a problem due to the lack of a design-time interface and the extra code required to hook up controls to their events. Once again, the folks at Microsoft realized that this was a major pain for SharePoint developers, and in SharePoint 2010 introduced the Visual Web Part. A Visual Web Part is a web part that loads an embedded user control. Since user controls have a design-time interface in Visual Studio, creating complex web parts becomes much simpler.
To create a Visual Web Part, take the following steps:
Share Point 2010 Related Interview Questions
|Web Services Interview Questions||XML Interview Questions|
|Share Point 2010 Interview Questions||ASP.NET Interview Questions|
|Share Point Administration Interview Questions||BizTalk Admin Interview Questions|
|Microsoft Office SharePoint Server (MOSS) Interview Questions||Biztalk Server Interview Questions|
|Asp Dot Net Mvc 4 Interview Questions||Biztalk Esb Toolkit Interview Questions|
|InfoPath Interview Questions|
Share Point 2010 Tutorial
The Microsoft Sharepoint 2010 Platform
Developing With Sharepoint 2010
Presentation Layer Overview
Client Object Model
Infopath Forms Services
Enterprise Content Management
User Interface Customization
Application Services Overview
Service Application Framework
Word Automation Services
Data Access Overview
Linq To Sharepoint And Spmetal
Business Connectivity Services
User Profiles And Social Data
Packaging And Deployment Model
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.