zoukankan      html  css  js  c++  java
  • ASP.NET中动态应用主题

    前言:看到360有个切换皮肤的功能是不是觉得很炫,好吧,今天我也来实现一下类似的功能。不知道和360的原理是不是一样的。

    在页面中动态应用主题主要是通过处理页面的Page_PreInit事件,在请求页面中,这是第一个被触发的事件,而在其后的Load和PreRender事件是不能动态应用主题的。

    另外说一下,动态应用母版的原理页是类似的。

    首先在App_Themes文件夹下创建两个不同的主题Green和Red,便于对比。主题下面有两个不同的Label.Skin文件:GreenLael.Skin和RedLabel.Skin两者的区别是Label控件一个设置为绿色一个设置为红色。

    好啦,下面是关键代码:

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
    protected void Page_PreInit(Object sender,EventArgs e)
    {
    if(Request["theme"]!=null)
    {
    switch (Request["theme"])
    {
    case "Green":
    Page.Theme= "GreenLabel";
    break;
    case "Red":
    Page.Theme = "RedLabel";
    break;
    }
    }
    }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:Label Text="动态应用主题请点击选择" runat="server" ID="lblSelect"></asp:Label>
    <ul>
    <li>
    <a href="动态应用主题.aspx?theme=Green">Green Theme</a>
    </li>
    <li>
    <a href="动态应用主题.aspx?theme=Red">Red Theme</a>
    </li>
    </ul>
    </div>
    </form>
    </body>
    </html>

    具体的代码大家自己去分析,我要去上课啦。谢谢多多吐槽!

  • 相关阅读:
    mybatis-plus解析
    ybatis中查询出多个以key,value的属性记录,封装成一个map返回的方法
    mybatis-plus分页记坑
    ComponentScan注解的使用
    fastJson序列化
    SpringBoot-RestTemplate测试Controller
    configparser模块
    python 将乱码转为汉字
    1.x 版本Django对应rest_framework版本
    docker容器内执行linux的dmidecode命令
  • 原文地址:https://www.cnblogs.com/luodao1991/p/2933700.html
Copyright © 2011-2022 走看看