第一步:从 http://www.dotnettreats.com/downloadfiles/SampleThemes.zip 下载一个简单你的asp.net应用程序。第二步:把zip释放,将其中 App_Themes 复制在您的网站下。第三步:在网站中添加一个ascx文件,然后把下面的代码拷入覆盖:<%@ Control Language="VB"%><script runat="server"> Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Me.Response.Cookies("theme, per user per site").Value = Me.DropDownList1.SelectedValue
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "reload", "setTimout(""window.location.reload()"",1)", True)
End Sub
</script><asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem>MSN_Blue</asp:ListItem>
<asp:ListItem>MSN_CherryBlossom</asp:ListItem>
<asp:ListItem>MSN_Finance</asp:ListItem>
<asp:ListItem>MSN_Morning</asp:ListItem>
<asp:ListItem>MSN_Purple</asp:ListItem>
<asp:ListItem>MSN_Red</asp:ListItem>
<asp:ListItem>WinXP_Blue</asp:ListItem>
<asp:ListItem>WinXP_Silver</asp:ListItem>
</asp:DropDownList>
如果你喜欢c#代码,可以自己转换一下。不过如果这个可以运行,何必转换呢。第四步:为您的页面从代码源窗口添加一个方法:
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
var s = Request.Cookies["theme, per user per site"];
if (s != null && s.Value != null)
this.Theme = s.Value;
}
第五步:为您的页面从设计窗口用鼠标拖入上面的ascx。
好了,这就可以运行了。您的页面在运行时就可以选择并记住用户的theme。如果您将第四步的代码在其它页面也增加,或者作为父类继承,那么那些页面就自动变化了。在您开发好asp.net程序之后,再让美工去编辑theme文件,界面的这类设计工作可以放到客户售后服务环节。开发时不要过分关注样式。
Me.Response.Cookies("theme, per user per site").Value = Me.DropDownList1.SelectedValue
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "reload", "setTimout(""window.location.reload()"",1)", True)
End Sub
</script><asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem>MSN_Blue</asp:ListItem>
<asp:ListItem>MSN_CherryBlossom</asp:ListItem>
<asp:ListItem>MSN_Finance</asp:ListItem>
<asp:ListItem>MSN_Morning</asp:ListItem>
<asp:ListItem>MSN_Purple</asp:ListItem>
<asp:ListItem>MSN_Red</asp:ListItem>
<asp:ListItem>WinXP_Blue</asp:ListItem>
<asp:ListItem>WinXP_Silver</asp:ListItem>
</asp:DropDownList>
如果你喜欢c#代码,可以自己转换一下。不过如果这个可以运行,何必转换呢。第四步:为您的页面从代码源窗口添加一个方法:
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
var s = Request.Cookies["theme, per user per site"];
if (s != null && s.Value != null)
this.Theme = s.Value;
}
第五步:为您的页面从设计窗口用鼠标拖入上面的ascx。
好了,这就可以运行了。您的页面在运行时就可以选择并记住用户的theme。如果您将第四步的代码在其它页面也增加,或者作为父类继承,那么那些页面就自动变化了。在您开发好asp.net程序之后,再让美工去编辑theme文件,界面的这类设计工作可以放到客户售后服务环节。开发时不要过分关注样式。
麻烦自己重新复制这一行吧。
Me.Response.Cookies("theme, per user per site").Value = Me.DropDownList1.SelectedValue
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "reload", "setTimeout(""window.location.href=window.location.href"",1);", True)
End Sub
</script><asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem></asp:ListItem>
<asp:ListItem>MSN_Blue</asp:ListItem>
<asp:ListItem>MSN_CherryBlossom</asp:ListItem>
<asp:ListItem>MSN_Finance</asp:ListItem>
<asp:ListItem>MSN_Morning</asp:ListItem>
<asp:ListItem>MSN_Purple</asp:ListItem>
<asp:ListItem>MSN_Red</asp:ListItem>
<asp:ListItem>WinXP_Blue</asp:ListItem>
<asp:ListItem>WinXP_Silver</asp:ListItem>
</asp:DropDownList>
你的帖子对我启发很大
呵呵,我是用Profile做的。没用Cookies
下面这句代码太关键了,采用脚本刷新页面以触发OnPreInit事件
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "reload", "setTimout(""window.location.reload()"",1)", True)