关于ASP.Net 2.0中的Theme

1、Theme和CSS的定义
Themes are not the same thing as cascading style sheets.
Cascading style sheets enable you to control the appearance of HTML tags on the browser.
Themes, on the other hand, are applied on the server and they apply to the properties of ASP.NET controls. For example, you can use a theme, but not a cascading style sheet, to specify whether or not a GridView control displays a header or footer.
也就是说Theme针对ASP.Net Server Controls而CSS针对HTML中的Tags

2、Theme(主题)是在后缀名为.skin的皮肤文件中定义的

3、Default Skin和Named Skin
如果ASPX中的Server Control没有指明Control ID,则将应用Default Skin,否则将使用名称一致的Named Skin。注意如果要应用Theme,首先必须ASPX文件的头部即在Page指令中定义Theme,如下所示:
<%@ Page Theme="OrangeTheme" %>

4、将Theme应用到整个应用
在Web.Config文件中加入黑体所示的代码
<configuration>
    <system.web>
  <pages theme="OrangeTheme" />
    </system.web>
</configuration>

5、Theme和StyleSheetTheme
当应用Theme时,Theme中的属性的优先级要高于Server Control中指定属性的优先级。
而通过应用StyleSheetTheme,则可以使Server Control中的属性覆盖StyleSheetTheme中的属性。

6、Theme和CSS
可以将CSS文件放入Theme所在的文件夹,当页面应用Theme时,将自动应用CSS。

7、Theme要比CSS灵活一点,这主要体现在可以通过代码对Theme进行设置和访问。这样就可以很方便地定制用户喜爱的显示方式。
<%@ Page Language="VB" %>
<script runat="server">
    Sub Page_PreInit(ByVal sender As Object, ByVal e As EventArgs)
        Page.Theme = Request("dropTheme")
    End Sub
</script>
<html>
<head id="Head1" runat="server">
    <title>Dynamic Theme</title>
</head>
<body>
    <form id="form1" runat="server">
    
    <asp:DropDownList
        id="dropTheme"
        AutoPostBack="true"
        Runat="Server">
        <asp:ListItem Text="YellowTheme" />
        <asp:ListItem Text="RedTheme" />
    </asp:DropDownList>

    </form>
</body>
</html>


参考网址Creating Web Application Themes in ASP.NET 2.0




posted on 2005-08-14 15:24  enjoy .net  阅读(621)  评论(1编辑  收藏  举报