The Theme function in asp.net 2.0

Source: Internet
Author: User
asp.net

ASP.net 2.0 adds a new Theme feature that makes it easier for Web sites to change skin.

The implementation of Theme includes: CSS, Skin, MasterPage.

CSS is used to control the appearance of all HTML tags.

Skin is used to control the appearance of all ASP.net server adjustments and can define its CSS styles through property cssClass.

MasterPage is a *.aspx page template, but it is not defined in Theme.

------------------------------------------------

• Create an example of Theme:

1, create the App_Themes directory in the Web project. It is a predefined directory, and ASP.net 2.0 automatically identifies the Theme in its directory.

2, in the App_Themes directory to create Orangetheme, bluetheme two subdirectories.

3. Add Skin files for each subdirectory under App_Themes, such as Control.skin. ASP.net 2.0 automatically analyzes each Skin file, where the name only needs to be easy to categorize for development.

4, you can also add CSS files for each subdirectory under App_Themes. ASP.net 2.0 will also automatically add each CSS file to every page that uses this style.

• Define page content and Theme style

1, Default.aspx page definition is as follows:

<%@ Page theme= "Orangetheme"%>
<title>orange page</title>
<body>
<form id= "Form1" runat= "Server" >
Enter your name:<br/>
<asp:textbox id= "txtname" runat= "Server"/>
<br/><br/>
<asp:button id= "btnsubmit" text= "Submit Name" runat= "Server"/>
</form>
</body>

2. The Control.skin file in the Orangetheme homepage is defined as follows:

Note: You can only specify appearance attributes, and you cannot specify properties such as Autopastback.

The default unnamed Skin will define skins for all TextBox types.

<asp:textbox backcolor= "Orange" forecolor= "Darkgreen" runat= "Server"/>
<asp:button backcolor= "Orange" forecolor= "Darkgreen" font-bold= "True" runat= "Server"/>

The named SkinID will be able to define the appearance for the specified TextBox type.

<asp:textbox skinid= "Title" backcolor= "Orange" forecolor= "Darkgreen" runat= "Server"/>

• Use Theme in the page

1, add the Theme= "Default" attribute to the top of the Aspx file <%@ Page%>. This allows it to use the Default theme.

2, if you think of the entire site to apply a Theme need to be defined in Web.config.

<configuration>
<system.web>
<pages theme= "Orangetheme"/>
</system.web>
</configuration>

This definition is equivalent to the default one Theme in all Web site files, you can still define Theme for each page when you use it.
The Skin section uses the Theme defined in the page surface, and CSS overloads the CSS style sheet in the default home page.

3, after the designation good Theme all appearance will use Skin to define. You can also specify the SkinID of the control to define a separate appearance.

4, if you want to programmatically define Theme must be handled in the Page_PreInit event, as follows:

void Page_PreInit (object sender, EventArgs e)
{
Page.theme = request["ThemeName"];
This definition is also required if you need to programmatically load the MasterPage file for the Page.
This. MasterPageFile = request["MasterPageFile"];
}

Understanding these technologies will make the site more changeable.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.