IT tutorials
 
Applications Server
 

Microsoft SharePoint 2010 : WebParts and SharePoint Pages - Writing Visual WebParts

4/20/2013 2:46:46 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Next, you are going to start writing WebParts using Visual Studio 2010. These WebParts are deployed using WSP's or solution packages. The first kind of WebPart you will write is a Visual WebPart. The word visual simply refers to the fact that you get visual editing experience when developing this WebPart in Visual Studio. This is possible because a Visual WebPart is based on an ASCX, also known as a user control. This WebPart being an ASCX also presents a significant limitation. The deployment of this WebPart requires an ASCX file to be copied on the file system. Since the deployment requires you to make changes to the file system, a Visual WebPart always has to be deployed as a farm solution.

NOTE

The other kind of WebPart, simply known as "WebPart" can also present visual elements on a SharePoint page. Visual WebPart simply refers to the Visual Editing Experience during Development. Visual WebPart is based on a User Control; the other WebPart is a server control.

However, the visual editing experience during development is quite useful as well. Let's go ahead and master this technology of developing a Visual WebPart.

Start by creating a new solution in Visual Studio 2010 and base it on the Visual WebPart project type. Note that SharePoint asks you which web site you intend to debug this solution on, but it does not allow you to create it as a sandbox solution. Once your solution is created, Visual Studio will open the ASCX file that will contain the UI for your Visual WebPart. You can go ahead and give your feature a proper name, by renaming your files to something meaningful. However, the examples stick with the default names for brevity.

Once the ASCX opens, you can use various controls that ship with SharePoint and ASP.NET to build a UI for your Visual WebPart. You may also write code-behind to enhance the logic of your Visual WebPart. This can be done by right-clicking the Visual WebPart ASCX and choosing view code.

However, this example uses only declarative code in the ASCX to demonstrate a way of showing the countries list using both SharePoint and ASP.NET controls. To achieve this, go ahead and add the code shown in Listing 1 in your ASCX.

Example 1. Visual WebPart Code
<h1>My Visual WebPart</h1>
<br />

<SharePoint:SPDataSource runat="server" ID="countriesList" DataSourceMode="List" SelectCommand="<Query><OrderBy><FieldRef Name='Title'
Ascending='true'/></OrderBy></Query>">
  <SelectParameters>
    <asp:Parameter Name="ListName" DefaultValue="Countries" />
  </SelectParameters>
</SharePoint:SPDataSource>

<asp:GridView ID="GridView1" runat="server" DataSourceID="countriesList"

					  

EnableModelValidation="True" AutoGenerateColumns="False"
  AllowPaging="True">
  <Columns>
    <asp:BoundField DataField="Title" HeaderText="Country Name"/>
    <asp:BoundField DataField="Population" HeaderText="Country Population" />
  </Columns>
</asp:GridView>

					  

Note that the code used for this ASCX uses both SharePoint controls and ASP.NET controls running in tandem.

Go ahead and build then deploy your solution. Note that this is a farm solution so it will do an IISReset. Drop the WebPart on the homepage of your site collection, and you should see the WebPart in action, as shown in Figure 1.

Figure 1. Your Visual WebPart in action
 
Others
 
- Microsoft SharePoint 2010 : WebParts and SharePoint Pages - Using SharePoint Designer with WebParts
- BizTalk Server 2009 : Do You Really Need an Orchestration?
- BizTalk Server 2009 : What the Orchestration Engine Provides
- SharePoint 2010 : Setting up Visio Services
- SharePoint 2010 : Setting up PerformancePoint Services
- SharePoint 2010 : Setting up Excel Services
- High Availability in Exchange Server 2010 : Developments in High Availability (part 3) - Online Move-Mailbox, Backup and restore
- High Availability in Exchange Server 2010 : Developments in High Availability (part 2) - Configuring a Database Availability Group, Managing database copies
- High Availability in Exchange Server 2010 : Developments in High Availability (part 1) - Exchange database replication, Database Availability Group and Continuous Replication
- High Availability in Exchange Server 2010 : Exchange Server database technologies
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us