http://www.codeproject.com/useritems/dynamicThemes.asp 可以下載Demo,有源碼,也有Article,應該就是你所需要的
解决方案 »
- 请问Attributes属性
- webservice中的session问题
- 如何获得GridView中templateField中选定行的控件
- 关于Cookie当购物车
- 掉用存储过程返回值问题
- 100分请教用delphi调用c#写的dll的问题!
- 请问一个统计读取的问题?
- 100问一个关于在asp.net web service中调用主页面中元素以及事件的问题!!!!!!!
- 求教!vs.net开发asp.net出现大问题,请专家看看
- html 的button1,当作为“服务器控件运行"时。怎会运行不到button1_serverclick事件?
- 请教:dataset,datareader的详细用法。。。
- 100分求 iis配置ssl win2003如何配置可信任的有效证书
这一句有问题吧,代码能详细点吗?
我看MSDN上说只能在 Page_PreInit内设置主题啊
public class BasePage : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
……
……
base.OnPreInit(e);
}
}
OK,我把代码贴全了
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ThemeDemo.aspx.cs" Inherits="ThemeDemo" StylesheetTheme="RedTheme" %><!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>Theme Demos</title>
</head>
<body>
<form id="form1" runat="server"> <asp:Label ID="Label3" runat="server" Text="选择页面主题"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Value="YellowTheme" Selected="True">Yellow</asp:ListItem>
<asp:ListItem Value="RedTheme">Red</asp:ListItem>
</asp:DropDownList>
<br /><br /><br />
<table class="tableStyle">
<tr>
<td style="height:23px" colspan="2" class="tdStyle"></td>
</tr>
<tr>
<td style="width: 160px; text-align: right">
<asp:Label ID="Label1" runat="server" Text="您的名字"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 160px; text-align: right">
<asp:Label ID="Label2" runat="server" Text="您的昵称"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Button ID="Button2" runat="server" Text="Button" /></td>
</tr>
<tr>
<td style="height:23px" colspan="2" class="tdStyle"></td>
</tr>
</table>
</form>
</body>
</html>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 ThemeDemo : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
this.Theme = Request.QueryString["DropDownList1"];
}
protected void Page_Load(object sender, EventArgs e)
{ }
}
问题就是选择后不更新主题。
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 ThemeDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Page_PreInit(object sender, EventArgs e)
{
Page.Theme = Request.QueryString["DropDownList1"];
}
}
{
if(Session["theme"]!=null)
Page.Theme = (string)Session["theme"];
} void DropDownList1_SelectedIndexChanged(object sender,.....)
{
Session["theme"]=DropDownList1.SelectedValue;
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "reload",
this.Page.ClientScript.GetPostBackEventReference(this,null), true);
}不一定使用Session。这里仅仅是偷懒举例而已。实际情况中,往往还可以使用数据库、cookie等。
{
if (Session["Theme"] != null)
{
Page.Theme = Session["Theme"].ToString();
}
else
{
Session["Theme"] = "YellowTheme";
Page.Theme = Session["Theme"].ToString();
}
} protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["Theme"] = RadioButtonList1.SelectedValue;
}我晕了,我换了个控件RadioButtonList1,里面有两个item
text:Yellow value:YellowTheme
text:Red value:RedTheme现在能换主题了,可出来怪毛病了,我点Yellow,他变成红色,我点Red他变成黄色。晕了,我theme里颜色没有写反,这是为什么吗
永远在
page_load()方法
执行之前,所以才出现以上问题!