The default display style on the page is too simple, and the page-by-page settings control's display style is too inefficient, and themes and skins provide an efficient design solution.
I. Adding a theme
two. Add skin files (. Skins):
Add the following code to the skin file
<
Asp:treeview
runat= "Server"
Showlines
= "True"
expanddepth
= "0" >
<
NodeStyle
font-size= "12px" forecolor= "Blue"/>
<
Selectednodestyle
backcolor= "#0A246A" font-size= "12px "
forecolor= "White"/>
<
/asp:treeview
>
three. Add CSS file (optional. css)
under the same folder as the theme you want
Body
{
font-size:12px;
margin:0px;
Cursor:default;
Font-family:tahoma, Verdana;
background-color: #F2F2F2;
}
. Commontext
{
font-size:12px;
}
. Msgtext
{
font-size:12px;
color:red;
}
. PromptText
{
font-size:16px;
color: #3795D2;
}
. Btnstyle
{
font-size
: 12px;
text-decoration
: none;
Background-color
: #FFFFFF;
Border-style
: Groove
}
in the same folder with him . Skin Add the following code
<asp:treeview runat= "Server" showlines= "True" expanddepth= "0" >
<nodestyle font-size= "12px" forecolor= "Blue"/>
<selectednodestyle backcolor= "#0A246A" font-size= "12px "
forecolor= "White"/>
</asp:TreeView>
<asp:
Label
runat= "Server"
CssClass
= "Commontext" ></asp:Label>
<asp:
Label
runat= "Server"
CssClass
= "Msgtext"
SkinID
= "Msgtext" ></asp:Label>
<asp:
Label
runat= "Server"
CssClass
= "PromptText"
SkinID
= "PromptText" ></asp:Label>
<asp:dropdownlist runat= "Server"
cssclass= "
Commontext
"></asp:DropDownList>
<asp:textbox runat= "Server" cssclass= "Commontext" ></asp:TextBox>
<asp:
Button
runat= "Server" cssclass= "Btnstyle" width= "65px"/>
<asp:
Button
runat= "Server" cssclass= "Btnstyle" skinid= "nowidthbtn"/>
where SkinID is the label we assign
This is the theme file created. --------------------------------------------------------------------------------------------------------------
First, Introduction:
With themes we can easily change the style of the controls and pages without having to modify our code and page files. The themes file is placed separately under the 1 App_Themes folders and is completely separate from your program.
Second, how to use themes and skins:
Let's look at a very simple example:
app_themes\default\1.skin file code:
Default.aspx: File code:
<%@ page language= "C #" theme= "Default"%>
! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0
transitional//en "" Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Page with Example Theme applied
You can see that we have not written in Default.aspx how to control the style code, but run to find the word on the label has become bold red, this is a most basic theme example.
App_Themes folder:
App_Themes folder is located at the root of the program, App_Themes must be a subfolder of theme name, and subfolders can contain multiple. Skins and. css files. Set up 2 theme in the default and Default2 names, respectively:
Using themes
1. Apply theme to 1 pages:
If you want to apply Theme to a 1 page, modify <%@ page theme= "..." directly in the ASPX file%>, for example you want this page to apply Default2 Theme, set <%@ page theme= "default2"%> OK
2. Apply the same 1 theme on all pages:
If you want to use the same theme on all pages, add a sentence node in Web. config.
3. Let the control not apply theme:
In the 1th example, we see that the style of the 2 labels has changed, that is, the style in the skin file has worked for all labels on the page. But sometimes we want some 1 labels to not apply. The style in the skin, when you just set the label's enabletheming property to False.
Maybe you want different labels to show different styles, you just have to set the label's SkinID property on it, see the following example:
App_themes\default\1.skin
skinid= "Blue" font-bold= "true" forecolor= "blue"/>
Deafult.aspx
<%@ page language= "C #" theme= "Default"%>
! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Page with Example Theme applied
skinid= "Blue" />
When you run it, you'll find that the 2 labels show different styles.
4. Other methods:
As already said in the ASPX file header using the <%@ page theme= "..."%> to use Theme, and using this method to apply the Theme style will overwrite the control property style you wrote in aspx. Like what:
App_themes\default\1.skin
Default.aspx
<%@ page language= "C #" theme= "Default"%>
! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Run the result, all the label's ForeColor are red.
Instead of using the <%@ page stylesheettheme= "..."%> app theme will not overwrite the properties you write in the ASPX file style:
Control to apply the Style property in the following order:
A, StyleSheetTheme-referenced style
B, code-set control properties (overwrite StyleSheetTheme)
C, theme reference style (covering the previous 2)
The theme contains CSS:
The. css file can also be used in theme, and when you put the. css file in the 1 theme directory, you will automatically apply your. css in this theme page.
Third, the backstage code easy for the website to change the house skin
All of the above is the application of theme in the ASPX file or Web. config, and it is obviously inconvenient for each user in the blog to have a different skin site with the method above to achieve the skin change.
The following describes how in the background code in the dynamic reference theme to solve the above situation, theme must be in the Page is requested at the earliest application, so we have to write code in the page_preinit event, the code is very simple, 1 sentences:
Page.theme = "...";
Here we simply read the different theme names of each user setting from the database to make it easy for each user to have a different skin.
Where do I add the Page_PreInit event?
I. Write the override vs Smart Prompt rewrite Onpreinit in the CS class of the page
C # code
protected override void Onpreinit (EventArgs e)
{
This. Page.theme = "Blue";
}
Two. Writing code manually
protected override void Onpreinit (EventArgs e)
{
This. Page.theme = "Blue";
}
ASP. NET Theme "1"