Figure 9-11: The final web part UI in the designer in .NET

Generation QR in .NET Figure 9-11: The final web part UI in the designer
Figure 9-11: The final web part UI in the designer
Generating QR In .NET
Using Barcode creator for Visual Studio .NET Control to generate, create QR Code image in VS .NET applications.
So far the experience of creating a visual web part hasn t been much different from creating an ASPNET user control Now that we have created the UI for the web part we need to write some code Double click the Create Task button to create an event handler for it Visual Studio displays the code view for VisualWebPart1UserControlascx as shown in Figure 9-12 Don t get confused by Source View and Code View Source View is a view in the designer that shows the markup of the user control VisualWebPart1UserControlascx Code view is the code-behind view of the code file associated with the ASPNET user control called VisualWebPart1UserControlascxcs
QR Code Reader In .NET Framework
Using Barcode scanner for VS .NET Control to read, scan read, scan image in VS .NET applications.
9: SharePoint Web Parts
Barcode Encoder In .NET Framework
Using Barcode encoder for .NET framework Control to generate, create bar code image in Visual Studio .NET applications.
Figure 9-12: Code view for the web part UI in the designer
Scan Barcode In VS .NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
Let s add some code to create a new SharePoint task First we need to add the following using directive to the code file:
Printing Denso QR Bar Code In Visual C#.NET
Using Barcode creation for VS .NET Control to generate, create Denso QR Bar Code image in VS .NET applications.
  
QR Code ISO/IEC18004 Creator In VS .NET
Using Barcode generation for ASP.NET Control to generate, create QR Code 2d barcode image in ASP.NET applications.
We don t need to add a reference to MicrosoftSharePoint because the visual web part project template in Visual Studio already has a reference to the MicrosoftSharePoint assembly The MicrosoftSharePoint assembly contains the SharePoint server side object model, which we will use to add a SharePoint task (See 3, Introduction to the SharePoint Object Model, for more information on SharePoint object models) With the using statement added to our code file, we can go ahead and implement the code for the event handler uxCreateTask_Click We want the event handler to create a new task in the task list Listing 9-2 shows code that creates a new task
Encoding QR Code In VB.NET
Using Barcode generation for Visual Studio .NET Control to generate, create Denso QR Bar Code image in .NET framework applications.
Listing 9-2: Code for Creating a Task in the CreateTaskWebPart s uxCreateTask_Click event handler
UCC.EAN - 128 Creator In .NET Framework
Using Barcode generation for Visual Studio .NET Control to generate, create GS1-128 image in .NET framework applications.

Create ECC200 In .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create Data Matrix 2d barcode image in VS .NET applications.
          
Make UPC - 13 In Visual Studio .NET
Using Barcode printer for .NET framework Control to generate, create EAN13 image in .NET framework applications.
Creating a Visual Web Part
Make UPC Symbol In VS .NET
Using Barcode encoder for .NET framework Control to generate, create UPC Code image in .NET applications.
        
Draw Leitcode In Visual Studio .NET
Using Barcode maker for Visual Studio .NET Control to generate, create Leitcode image in .NET framework applications.
Before we can create a task we need to get the Task list In the first line of the code in Listing 9-2, we create an SPSite object from the current context This gives us access to the site collection of the site where our web part is hosted Once we obtain the site object we need to get the web object, which represents the SharePoint site where the task list resides Because the SPSite is returned by the SPContext we don t need to dispose of it (an SPSite object returned by an SPContext object is managed by the SharePoint framework and should not be explicitly disposed in your code) The SPWeb object however must be instantiated in a using directive because it implements the IDisposable interface and must be cleaned up properly With the SPWeb object created we can access the task list and update its properties (See 4, SharePoint Lists, for more information on working with lists) Before we test our web part we should change its title Remember that the webpart file contains the Title property for web parts Double click the webpart file in the solution explorer and edit the XML to change the Title property to CreateTaskWebPart and the Description property to This web part creates new tasks in the task list The XML should now look like Listing 9-3
Painting Bar Code In Visual Studio .NET
Using Barcode generation for ASP.NET Control to generate, create barcode image in ASP.NET applications.
Listing 9-3: webpart File for CreateTaskWebPart
Barcode Creator In VB.NET
Using Barcode generation for .NET Control to generate, create bar code image in .NET framework applications.
                        
Painting UPC Symbol In Java
Using Barcode creation for Java Control to generate, create UPC Symbol image in Java applications.
9: SharePoint Web Parts
GS1 - 12 Scanner In Visual Studio .NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
  
Generate Bar Code In Java
Using Barcode creation for Java Control to generate, create bar code image in Java applications.
Shouldn t the Visual Web Part Title Get Updated When I Rename the VisualWebPart1 Project Item Folder
Making Code128 In Visual C#
Using Barcode maker for .NET framework Control to generate, create Code-128 image in .NET framework applications.
Renaming and refactoring are two weaknesses in Visual Web Part projects You can rename the VisualWebPart1 project item folder, but the webpart file will not have its title updated The same applies if you change the class name and namespace of the web part
GTIN - 12 Encoder In .NET Framework
Using Barcode printer for ASP.NET Control to generate, create GTIN - 12 image in ASP.NET applications.
Now it is time to test our web part Set a breakpoint on the first line of the code in Listing 9-2 and press F5 Visual Studio launches the browser with the site we specified when we created the project In order to debug our web part we should create a web part page first We could also add the web part to an existing web part page but by creating a new one and only adding our web part we will have better performance as well as better diagnostic possibilities as the page only needs to render our web part Also if the page throws an error we know that our web part and not some other web part on the page is causing the error In the Site Actions menu of the SharePoint site, select More Options as shown in Figure 9-13 In the Create dialog that appears as shown in Figure 9-14, click Page under Filter By: and then click Web Part Page and click the Create button The new web part page appears This page allows users to create web part pages and select various layouts for the page Layouts let you define how web parts are laid out on the page itself by specifying the layout and number of web part zones The create web part page also lets you choose a Save Location to store the new web part page Name the new page CreateTaskWebPartHost, leave the default template selected (Header, Footer, 3
Barcode Drawer In .NET
Using Barcode encoder for ASP.NET Control to generate, create bar code image in ASP.NET applications.