用按钮改变主题,怎么样?

时间:2011-05-04 11:35:26

标签: asp.net themes

我想在网站上使用2个主题,并且它们在主题文件夹中定位 - > theme1和theme2,在theme1和theme2中我有一个.css文件。 那么我将如何将这些.css文件连接到两个按钮,当我点击button1时,我想要theme1.css激活和for theme2。 如果您需要有关问题的更多信息请询问。 谢谢

2 个答案:

答案 0 :(得分:0)

在Page_PreInit中或插入代码之前

{
  this.Theme = "myTheme"
}

答案 1 :(得分:0)

我在asp.net中创建了一个示例应用程序,请查看此内容,如果有疑问,请告诉我。

<强>更新

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ProfilePage.aspx.cs" Inherits="ProfilePage" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="test" Text="Stackoverflow" runat="server"></asp:Label>
        <asp:Button ID="Button1" runat="server" Text="Theme1" OnClick="Button1_Click" />
        <asp:Button ID="Button2" runat="server" Text="Theme2" OnClick="Button2_Click" />
    </div>
    </form>
</body>
</html>




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        switch (Request.QueryString["theme"])
        {
            case "Blue":
                Page.Theme = "Blue";
                break;
            case "Red":
                Page.Theme = "Red";
                break;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("ProfilePage.aspx?theme=Red");
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("ProfilePage.aspx?theme=Blue");
    }
}