Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [178]

By Root 5335 0
if not explicitly deprecated. Why is this so? As I see things, the problem is not with themes but with the overall perception of server controls in ASP.NET development. Themes are just perfect—and more effective than CSS—if your language for expressing Web pages is largely based on server controls. If you don’t really feel the need to worry about what a server control emits, themes are just the perfect tool for the job.

At the height of ASP.NET’s success, the advent of AJAX silently started changing people’s perspective of things and led to a complete turnaround in only a couple of years. In a way, AJAX was the straw that broke the ASP.NET Web Forms abstraction model. With AJAX, you need much more control over the markup—HTML elements and CSS styles. Subsequently, many more developers are using server controls not as building blocks but rather as HTML helper factories. In this context, themes are simply a cumbersome technology compared to the flexibility and dynamism of CSS.

In any case, in this chapter you’ll find a section dedicated to the syntax and semantics of themes. CSS is a too large of a topic to be covered here. You can pick up one of the several books available on CSS. If you’re looking for an online reference, I recommend http://www.w3schools.com/CSS/CSS_reference.asp.

Note

Although themes are fully supported in ASP.NET 4, I currently see them mostly as a feature for a suite of controls rather than pages and sites. And I’m probably not the only one thinking this way. In the past couple of years, in fact, we’ve witnessed a significant technology shift that resulted in server controls becoming more and more HTML and CSS friendly. This trend is clearly visible in ASP.NET 4 (and future extensions are being currently planned). The perception is different—server controls must adapt their internal organization so that the output can be styled via CSS. If you take this route, of course, you just don’t need themes.

What’s a Theme, Anyway?


A theme is a set of visual settings that can be applied to style the markup produced by ASP.NET server controls. A theme is ultimately a collection of files—ASP.NET visual settings (known as skins), CSS, plus any auxiliary images. Once enabled, the theme determines the appearance of all controls under its jurisdiction. Consider the following simple markup:

Without themes, the calendar will look gray, spare, and spartan. With a theme added, the same markup renders a more colorful and appealing calendar. As you can see, a neat separation exists between the page contents and formatting rules. Look at Figure 8-9. Which do you think is the unthemed calendar?

Figure 8-9. The same controls, with and without themes.

To fully understand ASP.NET themes, you must be familiar with a few terms, which are detailed in Table 8-3.

Table 8-3. ASP.NET Themes Terminology

Term

Definition

Skin

A named set of properties and templates that can be applied to one or more controls on a page. A skin is always associated with a specific control type.

Style sheet

A CSS or server-side style sheet file that can be used by pages on a site.

Style sheet theme

A theme used to abstract control properties from controls. The application of this theme means that the control can still override the theme.

Customization theme

A theme used to abstract control properties from controls, but the theme overrides the control and any style sheet theme.

Imagine you are creating a new Web site and would like it to be visually appealing from the start. Instead of having to learn all the available style properties of each employed control, you just use ASP.NET themes. Using a built-in theme in a page is as easy as setting a property, as you’ll see in a moment. With this change, pages automatically inherit a new, and hopefully attractive, appearance. For example, if you add a Calendar control to a page, it automatically renders with the default appearance defined in the theme.

Selecting a theme for one or more pages doesn’t necessarily bind you

Return Main Page Previous Page Next Page

®Online Book Reader