dynamicweb7-8主题样式的切换,先在根目录中新建App_Themes文件夹,其中建立两个样式文件夹,一个Blue,一个Green。两个样式文件夹分别创建自己的. css .skin文件。Blue:skinfile1.skin
stylesheet1.css<asp:TextBox runat="server" BackColor="#99ccff" ForeColor="#6666ff" />
<asp:TextBox runat="server" SkinID="txtYellow" BackColor="LightYellow" />
<asp:Button runat="server" BackColor="#99ccff" ForeColor="#6666ff" BorderColor="#000066" BorderStyle="Solid" BorderWidth="1px" />
Green:skinfile2.skinbody {
background-color:#ecf0ff;
}
#top {
background:url("") center center no-repeat;
background-color:lightblue;
}
#left {
background:url("") center center no-repeat;
background-color:lightblue;
}
#footer {
background-color:lightblue;
}
stylesheet2.css<asp:TextBox runat="server" BackColor="#ccffcc" ForeColor="666699" />
<asp:TextBox runat="server" SkinId="txtYellow" BackColor="yellow" />
<asp:Button runat="server" BackColor="#ccffcc" ForeColor="666699" BorderColor="#336600" BorderStyle="Solid" BorderWidth="1px" />
创建母版页masterpage.master<asp:TextBox runat="server" BackColor="#ccffcc" ForeColor="666699" />
<asp:TextBox runat="server" SkinId="txtYellow" BackColor="yellow" />
<asp:Button runat="server" BackColor="#ccffcc" ForeColor="666699" BorderColor="#336600" BorderStyle="Solid" BorderWidth="1px" />
webform1.aspx<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage1.master.cs" Inherits="dynamicweb7_8.MasterPage1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
#top {
width:100%;
height:150px;
border:1px solid #cccccc;
}
#mid {
width100%;
min-height:560px;
border:1px solid #cccccc;
}
#mid #left {
width:180px;
height:560px;
float:left;
border:1px solid #cccccc;
}
#mid #main {
min-width:800px;
height:auto;
float:left;
}
#footer {
width:100%;
height:80px;
border:1px solid #cccccc;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="top">
<center><h4>Banner</h4></center>
</div>
<div id="mid">
<div id="left">
<ul>
<li><a href="WebForm1.aspx">首页</a></li>
<li><a href="WebForm1.aspx">首页</a></li>
<li><a href="WebForm1.aspx">首页</a></li>
<li><a href="WebForm1.aspx">首页</a></li>
</ul>
</div>
<div id="main">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
<div id="footer">
<center><h4>footer</h4></center>
</div>
</form>
</body>
</html>
webform1.aspx.cs<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="dynamicweb7_8.WebForm1" MasterPageFile="~/MasterPage1.Master" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div>
选择风格:
<asp:DropDownList ID="ddlTheme" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlTheme_SelectedIndexChanged">
<asp:ListItem Value="Blue">蓝色海洋</asp:ListItem>
<asp:ListItem Value="Green">绿色春天</asp:ListItem>
</asp:DropDownList>
</div>
<table style="border:1px solid #cccccc;background-color:white;width:300px;height:200px;text-align:center;">
<tr>
<td>
用户名:
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
密码:
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button1" runat="server" Text="登录" />
</td>
</tr>
<tr>
<td colspan="2">
单独指定主题:<asp:TextBox ID="TextBox3" runat="server" SkinID="txtYellow"></asp:TextBox>
</td>
</tr>
</table>
</asp:Content>
web.configusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace dynamicweb7_8
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["theme"] != null)
{
ddlTheme.SelectedValue = Session["theme"].ToString();
Session["theme"] = null;
}
}
}
protected void ddlTheme_SelectedIndexChanged(object sender, EventArgs e)
{
Session["theme"] = ddlTheme.SelectedValue;
Response.Redirect(Request.Path.ToString());
}
protected void Page_PreInit(object sender, EventArgs e)
{
//每个页面都这样操作,就是整体换肤
if (Session["theme"] != null)
{
Page.Theme = Session["theme"].ToString();
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<pages theme="Blue"></pages>
</system.web>
</configuration>