Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Web Pages
Themes
 How to: Apply ASP.NET Themes Progra...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:

Want more? Here are some additional resources on this topic:

ASP.NET 
How to: Apply ASP.NET Themes Programmatically 

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.

NoteNote

The themes referenced below are not included in ASP.NET. To create a custom theme, see How to: Define ASP.NET Themes.

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.

    Visual Basic
    Protected Sub Page_PreInit(ByVal sender As Object, _
            ByVal e As System.EventArgs) _
            Handles Me.PreInit
        Select Case Request.QueryString("theme")
            Case "Blue"
                <b>Page.Theme = "BlueTheme"</b>
            Case "Theme2"
                <b>Page.Theme = "PinkTheme"</b>
        End Select
    End Sub
    

    C#
    Protected void Page_PreInit(object sender, EventArgs e)
    {
        switch (Request.QueryString["theme"])
        {
            case "Blue":
                <b>Page.Theme = "BlueTheme";</b>
                break;
            case "Pink":
                <b>Page.Theme = "PinkTheme";</b>
                break;
        }
    }
    

To apply a style sheet theme programmatically

  • In the page's code, override the StyleSheetTheme property and in the get accessor, return the name of the style sheet theme.

    The following code example shows how to set a theme named BlueTheme as the style sheet theme for a page:

    Visual Basic
    Public Overrides Property StyleSheetTheme() As String
       Get
           Return "BlueTheme "
       End Get
       Set(ByVal value As String)
       End Set
    End Property
    

    C#
    public override String StyleSheetTheme
    {
      get { return "BlueTheme "; }
    }
    

To apply control skins programmatically

  • In a handler for the page's PreInit method, set the control's SkinID property.

    The following code example shows how to set the SkinID property of a Calendar control.

    Visual Basic
    Sub Page_PreInit(ByVal sender As Object, _
            ByVal e As System.EventArgs) _
            Handles Me.PreInit
        <b>Calendar1.SkinID = "BlueTheme"</b>
    End Sub
    

    C#
    void Page_PreInit(object sender, EventArgs e)
    {
        <b>Calendar1.SkinID = "MySkin";</b>
    }
    

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker