星期三, 11月 12, 2008

動態換佈景主題..

動態換佈景主題..這好像是大家常問的問題..今天試玩了一下..然後查了一下資料知道屬性的強制性是..

Page.Theme > 頁面定義的屬性 > Page.StyleSheetTheme

因為..我想比較靈活的去控制我的頁面..所以我會選擇動態去改Page.StyleSheetTheme這屬性..不過比較麻煩要處理的問題是..Page.StyleSheetTheme是唯獨的..查一下msdn也有建議的解決方法..看code比較快ㄅ..Big Grin..

這是我的app_themes

dfd

.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test"
ValidateRequest="false" StylesheetTheme="Theme1" %>

<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem>Theme1</asp:ListItem>
<asp:ListItem>Theme2</asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>

.cs

using System;
using System.Linq;

public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
public override string StyleSheetTheme
{
get
{
if (Request.Params.AllKeys.Contains("DropDownList1"))
return Request.Params["DropDownList1"];
return "Theme1";
}
set
{
base.StyleSheetTheme = value;
}
}
}

這樣就行了..有空自己玩玩ㄅ..HappyHappyHappyHappyHappyHappyHappy..

參考:

沒有留言: