【300分散掉】不要从空白开始设计界面,请从实例开始:从这个步骤开始使用 Theme

以专业开发人员为伍 2008-10-05 09:44:20
第一步:从 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文件,界面的这类设计工作可以放到客户售后服务环节。开发时不要过分关注样式。
...全文
1701 203 打赏 收藏 转发到动态 举报
写回复
用AI写文章
203 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2009-04-27
  • 打赏
  • 举报
回复
我用360浏览器调试的时候,换不了啊,后来用ie调试,报错了,不支持jscript,,这是为什么啊?
「已注销」 2009-04-27
  • 打赏
  • 举报
回复
我用了楼主的方法,怎么换不了啊,谁能帮帮我啊,qq365708921
doc123 2009-04-26
  • 打赏
  • 举报
回复
看了 接分
lily_0305 2009-04-26
  • 打赏
  • 举报
回复
thanks~
bagegejin 2009-04-25
  • 打赏
  • 举报
回复
呵呵,我的想法是写一个PageBase基类,创建一个Theme属性,然后重写OnPreRent()
MrCamel 2008-12-15
  • 打赏
  • 举报
回复
向楼主学习中。
pgameli 2008-12-10
  • 打赏
  • 举报
回复
怎么把
<script runat="server">
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
this.Theme = "MSN_Red";
HttpCookie s = Request.Cookies["theme, per user per site"];
if (s != null && s.Value != null)
this.Theme = s.Value;
}
</script>

转换成C#的代码啊
srobot 2008-12-02
  • 打赏
  • 举报
回复
搜藏。
walkghost 2008-11-26
  • 打赏
  • 举报
回复
学习了。。。
不过汗一下:

【300分散掉】不要从空白开始设计界面,请从实例开始:从这个步骤开始使用 Theme [无满意答案结帖,结帖人:sp1234]
cymyren 2008-10-20
  • 打赏
  • 举报
回复
刚才操作了一下
roycelwh 2008-10-17
  • 打赏
  • 举报
回复
再写个BasePage类,继承
guoheng90 2008-10-16
  • 打赏
  • 举报
回复
不知道什么意思哦
zoumengdiefly 2008-10-16
  • 打赏
  • 举报
回复
楼主真是强人,楼主真是好人,真希望世界上多一些像楼主这样的人!
ADVANTECH_CYZ 2008-10-15
  • 打赏
  • 举报
回复
haifeng
rightyeah 2008-10-15
  • 打赏
  • 举报
回复
up
wd1566 2008-10-15
  • 打赏
  • 举报
回复
真牛人也!收藏
hylovett 2008-10-09
  • 打赏
  • 举报
回复
正好可以学习..........
qq1021974 2008-10-09
  • 打赏
  • 举报
回复
厉害
NowtAngell 2008-10-09
  • 打赏
  • 举报
回复
..UP 收藏,接分
zhangxuyu1118 2008-10-08
  • 打赏
  • 举报
回复
[Quote=引用 132 楼 much0726 的回复:]
我有个问题:
在按lz的方法做了以后,
OnPreInit的执行先于DropDownList1_SelectedIndexChanged
也就是说,每次载入的Theme是上次选择的selectvalue.
不知道有没有人做出来了,还是和我一样的.
[/Quote]
没这个问题。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" StylesheetTheme="MSN_CherryBlossom"%>

<%@ Register Src="Base.ascx" TagName="Base" TagPrefix="uc1" %>

<!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>
<script runat="server">
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
this.Theme = "MSN_Red";
HttpCookie s = Request.Cookies["theme, per user per site"];
if (s != null && s.Value != null)
this.Theme = s.Value;
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:Base ID="Base1" runat="server" />
<br />
<h1>RWER</h1><br />
<h1>WRWERWER</h1></div>
</form>
</body>
</html>
加载更多回复(182)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧