In addition to specifying theme and skin preferences in page declarations and configuration files, you can apply themes programmatically. You can set both page themes and style sheet themes programmatically; however, the procedure for applying each type of theme is different.

To apply a page theme programmatically

In a handler for the page's PreInit method, set the page's Theme property.

The following code example shows how to set a page's theme conditionally based on a value passed in the query string.