![]() To set it in the Web.config file, you would use the styleSheetTheme attribute (rather than the Theme attribute), as in the following. You can also set the StyleSheetTheme via the Web.config file. For instance, in the following example, the "World" text is blue. As such, the StyleSheetTheme behaves in a manner more akin to the cascade within CSS. Unlike those applied by the Theme attribute, the properties applied by the StyleSheetTheme are overridden by control properties defined within the page. You can do so by changing the Page directive of the form and use the StyleSheetTheme attribute rather than the Theme attribute. There is another way to have properties defined within individual controls override skin settings. You can have a control ignore a skin setting via the EnableTheming property, as in the following. What text color will the content of these two Label controls have when rendered by the browser? In fact, both will be green, because skin definitions override page definitions. Now imagine that you use this skin in a page that contains the following markup. For instance, consider the following skin definition. Overriding ThemesĪs previously mentioned, skin definitions for a control type override any settings for that control type made within a given page. When the runtime executes a page that has a theme, it iterates through the page's Controls collection, and if there is a delegate for the control type, it calls the delegated method (in the generated skin class) which then decorates (i.e., changes the properties specified in the skin) the specific control object. This delegate represents or "points to" the actual method that applies the correct skin to the control this method exists in the class file generated for the skin. This class maintains a collection of ControlSkinDelegate objects. Recall from Chapter 2 that the markup in an aspx page is parsed into a class and then compiled into an assembly an analogous thing happens with the skin files-each theme is parsed and compiled into a separate assembly.Įach theme is realized as a concrete subclass of the PageTheme class. When a request arrives for a resource from an ASP.NET application that uses themes, the runtime parses and compiles all the skins in each theme. Like everything in ASP.NET, it all begins with a request. Now that you have seen how to create and use themes, let us peek under the hood and examine what ASP.NET does to make themes work. The specified theme folder and its contents must be located in the global theme space for the machine, located at \Microsoft.NET\Framework\ \ ASP.NETClientFiles\Themes. ![]() Just as with setting the theme for a site via the Web.config file shown earlier, you can set the global theme for the machine as a whole via the Theme attribute of the pages element within the system.web element of this nfig file. This file is located at \Microsoft.NET\Framework\ \CONFIG. Finally, another, less common way to set the theme is to set it for all sites on a machine via the nfig file. This is covered in more detail later in the chapter. To do so, you can set the Theme property (defined in the Page base class) for a form in its code-behind class. ![]() Themes that are specified via the Theme attribute of the Page directive override the theme setting in the Web.config file.Ī page's theme can also be set programmatically. You can create this folder yourself in Visual Studio by right-clicking the Web project in the Solution Explorer and choosing Add ASP.NET Folder → Theme option, as shown in Figure 6.4. ![]() Themes reside in separate folders within the App_Themes folder within your site. As an alternative, you could create a temporary Web Form, use the Design view or Source view as needed to add controls and set up their properties, copy and paste the markup to your skin file, and then remove the id attribute from each of the controls. Even worse, Visual Studio's Intellisense is not available in Source view when modifying a skin. That is, the only way to create and modify a skin file is directly in Source view within Visual Studio. There is no Visual Studio designer support for creating skins. However, you can make a control in a Web Form or user control ignore the settings in a skin by adding EnableTheming="false" to the control. This may seem counterintuitive from an object-oriented programming perspective, because you might expect the more specialized (the page) to override the general (the skin). It is important to note that property values specified by a skin override the property values set for the control in the aspx and ascx pages.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |