Using Barcode creation for ASP.NET Control to generate, create EAN-13 Supplement 5 image in ASP.NET applications.

www.OnBarcode.com

Customizing chrome At times we ll want to create a custom look for the outer area of our zones a look that will give all our pages a distinctive feel or flair. To do so, we create our own custom chrome class and write code within that class that performs custom rendering logic to suits our needs. To allow us to use custom chrome in the portal, each zone has a method that is responsible for returning the chrome type that should be used for rendering its parts. The methods for each of these three zones that return their chrome are WebPartZoneBase.CreateWebPartChrome EditorZoneBase.CreateEditorPartChrome CatalogZoneBase.CreateCatalogPartChrome Overriding these methods provides us with an interception point we can use to return our own chrome classes which contain custom rendering logic for rendering parts and their contents. To see how this works, take a look at listing 5.5 and notice the logic contained within its RenderPartContents and RenderWebPart methods:

Using Barcode encoder for Font Control to generate, create PDF417 image in Font applications.

www.OnBarcode.com

This custom chrome class shown in the preceding segment inherits from WebPartChrome and can therefore be returned as the chrome to be used by the CreateWebPartChrome method of a WebPartZone. In order for the chrome to be used by a zone, we must associate the chrome with the zone. In the case of a WebPartZone, we accomplish this by overriding the CreateWebPartChrome method and returning an instance of our custom chrome class. The following snippet shows a custom WebPartZone using our CustomWebPartChrome to perform web part rendering:

This final snippet shows us that every web part within the WebPart zone is rendered through the chrome, and not through the zone itself. 5.4.3 Viewing the results of custom chrome To appreciate the additional level of control gained over the rendering process by creating our custom chrome, we can now use the CustomWebPartZone to host some web parts and view the rendered output. Add the following markup to a page in your test project and run it to view the output.

Here our CustomWebPartZone class is declared within a page, and as we can see, it contains two web parts declared within its zone template. At runtime the RenderWebPart method of our custom chrome class will be called twice once for each web part contained within the zone. Figure 5.7 shows the results of the page being run in a browser. As we see, the text rendered from the RenderWebPart and RenderWebPartContents methods is displayed instead of the textbox web parts we d normally expect

WORKING WITH ZONES

Figure 5.7 This figure shows how the RenderWebPart and RenderWebPartContents methods affect the rendered output of web parts contained within a zone.

to see. To further highlight what s going on, we can remove the overridden RenderWebPart method we added to the custom chrome class. Removing this method from our custom chrome class means that the base class implementation of that method will be called at runtime and do all of its normal rendering of borders, titles and verbs so at least our parts will look like the web parts we ve seen in the past. Our custom RenderWebPartContents code will still run and render the body of the part as the text that we emitted: Part Contents. Figure 5.8 shows the output rendered when we remove the implementation we added for the RenderWebPart method. Working through the chapter to this point has provided a good look at the three main rendering methods for zones and we ve seen how the level of control from the combination of styles, zone rendering, and chrome rendering simplifies the task of creating the exact look and feel we want for parts within our portal. We ve also seen that each of these three methods of affecting the rendered output comes with a different level of difficulty. Using styles is relatively straightfor- Figure 5.8 By removing the code we wrote ward, while overriding the rendered sections within zones is for the RenderWebPart much more difficult because then we are attempting to create method, we make the web parts regain their a lot of visual elements and functionality. familiar look as the Now that we ve learned about the makeup of zones and verbs and title texts seen how to affect their visual elements, it s time to take a are also rendered in closer look within the EditorZone and the CatalogZone. the header area.