动态加载主题

先来目录:

 

css文件代码:(当然自己随意写吧,没多难)

 1 body 
 2 {
 3     text-align:center;
 4     color:Yellow;
 5     background-color:Navy;
 6 }
 7 A:link
 8 {
 9    color:White;
10    text-decoration:underline;    
11 }
12 A:visited
13 {
14     color:White;
15     text-decoration:underline;    
16 }
17 A:hover
18 {
19     color:Fuchsia;
20     text-decoration:underline;
21     font-style:italic;    
22 }
23 input 
24 {
25     border-color:Yellow;    
26 }
View Code

skin文件代码:(这个看看格式,注意下格式就行)

 1 <%--
 2 默认的外观模板。以下外观仅作为示例提供。
 3 
 4 1. 命名的控件外观。SkinId 的定义应唯一,因为在同一主题中不允许一个控件类型有重复的 SkinId。
 5 
 6 <asp:GridView runat="server" SkinId="gridviewSkin" BackColor="White" >
 7    <AlternatingRowStyle BackColor="Blue" />
 8 </asp:GridView>
 9 
10 2. 默认外观。未定义 SkinId。在同一主题中每个控件类型只允许有一个默认的控件外观。
11 
12 <asp:Image runat="server" ImageUrl="~/images/image1.jpg" />
13 --%>
14 <asp:TextBox runat = "server" text = "这是主题1" BackColor="#c0c0c0" BorderColor = "#7f7f7f"
15     ForeColor = "#004400" Font-Size = "12pt" width = "150pt" />
16 <asp:TextBox SkinID = "TextBoxSkin" runat = "server" text = "这是主题11" BackColor = "red" 
17     BorderColor = "green" ForeColor = "yellow" Font-Size = "15pt" width = "150pt" />
View Code

重点来了:

空网站添加DropDownList控件。设置属性如下:

  

点击后设置为

里面的Theme1和Theme2就对应目录里的。

当然上面也可以设置属性为,Theme = "Theme1",但这样就只能显示一个主题了╮(╯▽╰)╭。 

cs文件代码:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 using System.Web.Query;
 8 
 9 
10 public partial class _Default : System.Web.UI.Page
11 {
12     protected void Page_Load(object sender, EventArgs e)
13     {
14 
15     }
16     //Dropdownlist里的这个事件的作用是,每当选项发生改变时会触发一个事件
17     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
18     {
19         string url = Request.Path + "?theme=" + DropDownList1.SelectedItem.Value;
20         Response.Redirect(url);
21     }
22     void Page_PreInit(object sender, EventArgs e) {
23         string theme = "theme1";
24         if (Request.QueryString["theme"] == null)
25         {
26             theme = "theme1";
27         }
28         else {
29             theme = Request.QueryString["theme"];
30         }
31         Page.Theme = theme;
32         ListItem item = DropDownList1.Items.FindByValue(theme);
33         if (item != null) {
34             item.Selected = true;
35         }
36     }
37     protected void button1_Click(object sender, EventArgs e)
38     {
39 
40     }
41 }
View Code

好了,这就完成了。来,看结果。

还行。。。umumumy。

转载于:https://www.cnblogs.com/chenluomenggongzi/p/5528263.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值