EXPLORING WEB PARTS in Visual Studio .NET

Generate Data Matrix in Visual Studio .NET EXPLORING WEB PARTS

EXPLORING WEB PARTS
Print Data Matrix In .NET Framework
Using Barcode printer for ASP.NET Control to generate, create ECC200 image in ASP.NET applications.
www.OnBarcode.com
Paint Universal Product Code Version A In Visual Studio .NET
Using Barcode creator for ASP.NET Control to generate, create GS1 - 12 image in ASP.NET applications.
www.OnBarcode.com
Figure 2.3 While stepping through code in debug mode you can place the mouse cursor above variables to display their state.
Barcode Drawer In VS .NET
Using Barcode generation for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
QR Code Creation In .NET
Using Barcode printer for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
www.OnBarcode.com
Similarly, hovering over the countOfControls variable will display zero for its value. This tells us that the web part zone now believes that it contains no web controls. Hover over the last breakpoint and you ll see that the name of the Type of the web part is GenericWebPart as displayed in figure 2.4.
EAN-13 Supplement 5 Generator In .NET
Using Barcode creator for ASP.NET Control to generate, create EAN-13 image in ASP.NET applications.
www.OnBarcode.com
Barcode Maker In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
Figure 2.4 Displaying the Type of the web part at runtime shows that it is no longer a Label but is now a GenericWebPart control.
GS1-128 Drawer In Visual Studio .NET
Using Barcode generation for ASP.NET Control to generate, create GS1-128 image in ASP.NET applications.
www.OnBarcode.com
USPS PLANET Barcode Printer In .NET Framework
Using Barcode creator for ASP.NET Control to generate, create USPS Confirm Service Barcode image in ASP.NET applications.
www.OnBarcode.com
With the page still in debug mode, right-click on the wp variable and choose the Quick Watch menu option from the resulting context menu. In response, the Quick Watch dialog is displayed for the wp variable allowing us to see the values for all of its properties. Figure 2.5 displays the Quick Watch dialog with many of the properties for the wp variable shown. In the Quick Watch dialog we can see that the GenericWebPart has a large number of properties that do not belong to the Label class but, instead are members of the WebPart class. These properties include: IsClosed, Title, CatalogIconImageUrl, and ChromeState to name just a few. We see that there is also a property named WebBrowsableObject and that it is currently displaying a value of {Text = I m a label } the very same text value that we assigned to the original label in the mark-up for the page! This is quite a significant discovery, because it tells us that the very same Label control that we added to our WebPartZone earlier has been replaced with a new Type of control and has been wrapped by the WebBrowsableObject property. We can actually still get at the underlying Label control via the ChildControl property of the GenericWebPart as demonstrated by the
Painting DataMatrix In VB.NET
Using Barcode encoder for .NET Control to generate, create DataMatrix image in Visual Studio .NET applications.
www.OnBarcode.com
Creating ECC200 In C#.NET
Using Barcode drawer for .NET Control to generate, create Data Matrix image in Visual Studio .NET applications.
www.OnBarcode.com
WEB PARTS: THE BUILDING BLOCKS OF PORTALS
Reading Barcode In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
European Article Number 13 Printer In Java
Using Barcode creator for Java Control to generate, create EAN-13 image in Java applications.
www.OnBarcode.com
Figure 2.5 The Visual Studio 2005 Quick Watch window displays the runtime values of objects.
Code 128B Creation In None
Using Barcode printer for Font Control to generate, create Code-128 image in Font applications.
www.OnBarcode.com
UCC.EAN - 128 Maker In Objective-C
Using Barcode printer for iPad Control to generate, create EAN / UCC - 14 image in iPad applications.
www.OnBarcode.com
code in listing 2.1. Why would we want to get at the underlying control of the generic web part One reason might be that we are using a control such as a GridView as the child control and we need to access the GridView after a page postback to re-bind it to a data source control.
Draw UCC - 12 In Java
Using Barcode generator for Java Control to generate, create UPC-A Supplement 2 image in Java applications.
www.OnBarcode.com
ECC200 Maker In .NET Framework
Using Barcode generation for Reporting Service Control to generate, create Data Matrix ECC200 image in Reporting Service applications.
www.OnBarcode.com
Listing 2.1 The ChildControl property of the GenericWebPart provides access to the underlying web control that is wrapped by the GenericWebPart.
Barcode Drawer In Objective-C
Using Barcode drawer for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Drawing Barcode In None
Using Barcode encoder for Office Excel Control to generate, create Barcode image in Excel applications.
www.OnBarcode.com
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); int countOfControls = this.WebPartZone1.Controls.Count; int countOfWebParts = this.WebPartZone1.WebParts.Count; foreach (WebPart wp in this.WebPartZone1.WebParts) { if (wp is GenericWebPart) { Type t = ((GenericWebPart)wp).ChildControl.GetType();
Creating UCC - 12 In Java
Using Barcode drawer for Java Control to generate, create USS-128 image in Java applications.
www.OnBarcode.com
Universal Product Code Version A Creation In None
Using Barcode creator for Online Control to generate, create Universal Product Code version A image in Online applications.
www.OnBarcode.com
Cast the web part to a GenericWebPart to get at the ChildControl property
EXPLORING WEB PARTS
string typeName = t.Name; } } }
Returns "Label"
Having viewed the page at runtime, we saw that the portal framework elevated the label to the status of a web part by enclosing it within a GenericWebPart wrapper before adding it to the zone. This occurs for all non-web part controls that are added to web part zones, including user controls. Being able to create user controls and have them treated as web parts makes it possible to create web parts very rapidly and easily compared to the alternative which is to create web parts directly by inheriting from the WebPart class. To get a feel for some of the differences, let s take a look at what s involved when we create web parts by inheriting from the WebPart class. In doing so we ll better understand how to work directly with the WebPart class and we ll also get to see how web parts are rendered.
UNDERSTANDING THE WEBPART CLASS
Up until now, all the web parts that we ve seen have been created by simply adding server controls such as the Calendar and Label to zones within the page. Now it s time to learn about another kind of web part control a custom server control that directly inherits from the abstract WebPart base class. In this section we will create a web part by inheriting directly from the WebPart class and then learn how to add our custom web part to a web page by registering our custom web part class with the page. Dragging user controls onto zones and having them treated as web parts is fine when the web parts do not need to be shared outside a single application; but part of the power of web parts is that, by their very nature, they lend themselves well to being reused in more than just a single portal application. For reuse, user controls cannot surpass custom controls, because custom controls can be compiled into very specific assemblies and easily shared between applications. If you need to share web parts between your own applications, or indeed, package them for reuse by third parties, then you will want to create custom controls so that you can take advantage of the packaging of assemblies.To do this you will need to create custom classes that derive directly from the WebPart class. The WebPart class lives in the System.Web.UI.WebControls.WebParts namespace and serves as the base class for all web part controls. In fact, if you look at the definition of GenericWebPart, you will see that it does in fact inherit from the WebPart class. The WebPart class itself inherits from a base class named Part. The Part class has the basic properties that are relevant for all web part parts including editor parts and catalog parts such as description, title and a few others.
Using custom controls We ve just seen that, when creating web parts, we have two options. The first option is to create a class that derives directly from the WebPart class, and the second option
Copyright © OnBarcode.com . All rights reserved.