Themes
Themes are a way for you to define a consistent look and feel across your web site. They consist of files and properties that can include:
- Skins
- Style Sheets (CSS)
- Images
When you devleop a theme it will reside in a special directories in your web site. While themes can consist of many different elements at a minimun a theme consists of a skin.
Skins
A skin defines properties for the individual ASP.NET controls on your web site. Skin properties are created very similar to the way common controls are marked up but only contain the properties that you want to be part of the theme. For example, a skin for a Button control might look like this:
<asp:button runat="server" BackColor="lightblue" ForeColor="black" />
Skins are created in files with the extension .skin which you create inside a Theme folder. The can contain markup for a single control or a list of controls. It is also possible for you to create a skin file for each control.
There are basically two types of control skins:
- A default skin that is automatically applied to all the controls of the same type when the theme is applied to the page. A control skin is a default skin if it does not have a SkinID attribute. For example, if you create a default skin for a Calendar control, the control skin applies to all Calendar controls on pages that use the theme. (Default skins are matched exactly by control type, so that a Button control skin applies to all Button controls, but not to LinkButton controls or to controls that derive from the Button object.)
- A named skin is a control skin with a SkinID property set. Named skins do not automatically apply to controls by type. Instead, you explicitly apply a named skin to a control by setting the control's SkinID property. Creating named skins allows you to set different skins for different instances of the same control in an application.
Style Sheets (CSS)
A theme can also include a cascading style sheet (.css file). When you put a .css file in the theme folder, the style sheet is applied automatically as part of the theme.
Resources
Themes can also include graphics and other resources, such as script files or sound files. For example, part of your page theme might include a skin for a TreeView control. As part of the theme, you can include the graphics used to represent the expand button and the collapse button.
Typically, the resource files for the theme are in the same folder as the skin files for that theme, but they can be elsewhere in the Web application, in a subfolder of the theme folder for example. To refer to a resource file in a subfolder of the theme folder, use a path like the one shown in this Image control skin:
<asp:Image runat="server" ImageUrl="ThemeSubfolder/filename.ext" />
You can also store your resource files outside the theme folder. If you use the tilde (~) syntax to refer to the resource files, the Web application will automatically find the images. For example, if you place the resources for a theme in a subfolder of your application, you can use paths of the form ~/SubFolder/filename.ext to refer to resource files, as in the following example.
<asp:Image runat="server" ImageUrl="~/AppSubfolder/filename.ext" />