zoukankan      html  css  js  c++  java
  • 预初始化对象(OnPreInit)

     

    实现功能:动态控制网站程序中服务器控件的外观。

    实现步骤:

    在网站根目录下创建文件夹:App_Themes。这个文件夹名字不能改成别的。

    App_Themes文件夹下创建子文件夹(主题),这个子文件夹名称就是页面的主题名称

    在主题下添加.css,.skin等文件.

    示例:

    1 创建文件夹: App_Themes,在它下面添加两个主题: BlueThemeRedTheme.

    2 BlueTheme下添加文件BlueTheme.skin,写入内容:

    <asp:Button runat="server" BackColor="Blue" ForeColor="White" Font-Name="Arial" Font-Size="9px" />

    3 RedTheme下添加文件RedTheme.skin,写入内容:

    <asp:Button runat="server" BackColor="Red" ForeColor="White" Font-Name="Arial" Font-Size="9px" />

    4 HTML代码:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageLife.aspx.cs" Inherits="PageLife" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

        <title>无标题页</title>

    </head>

    <body>

        <form id="form1" runat="server">

        <div>

        <a href="PageLife.aspx?theme=Red" >red</a>

        <a href="PageLife.aspx?theme=Blue" >blue</a>

        <asp:Button ID="Button1" runat="server" Text="Button" />

        <asp:Button ID="Button2" runat="server" Text="Button" />

        </div>

        </form>

    </body>

    </html>

    5 .CS代码:

    using System;

    using System.Data;

    using System.Configuration;

    using System.Collections;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    public partial class PageLife : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

        }

        ///<summary>

        ///预初始化方法,在用户控件和模板页里没有这个事件

        ///</summary>

        ///<param name="e"></param>

        protected override void OnPreInit(EventArgs e)

        {

            //参考http://msdn2.microsoft.com/zh-cn/library/tx35bd89(vs.80).aspx

            base.OnPreInit(e);

            switch (Request.QueryString["theme"])

            {

                case "Blue":

                    Page.Theme = "BlueTheme";

                    break;

                case "Red":

                    Page.Theme = "RedTheme";

                    break;

            }

        }

    }

  • 相关阅读:
    Nuget相关设置
    MSBuild笔记-预留
    .NET Core笔记-File Providers(文件系统)
    JS混淆助手类
    .Net Core
    ASP.NET Core中间件
    ASP.NET Core中间件
    使用表达式树和反射来访问对象属性的性能比较【转】
    Newtonsoft.Json笔记 -ContractResolver
    Newtonsoft.Json笔记 -JsonConvert自定义序列化与反序列化
  • 原文地址:https://www.cnblogs.com/mimengjiangnan/p/947912.html
Copyright © 2011-2022 走看看