我正在创建一个具有多个高对比度主题的ASP网站。我创建了其他具有主题的网站,但这是第一个在选择新主题时不会改变的网站。我有一个理论,主题和皮肤文件不应该在文件夹或文件名中包含空格,但我不确定。任何建议都会很棒。这是我的下拉列表:
<asp:DropDownList ID="DDL_SwitchTheme" runat="server" CssClass="BigText">
<asp:ListItem Disabled="true" style="color: Silver;">High Contrast Themes</asp:ListItem>
<asp:ListItem style="color: Black; background-color: White; font-weight: bolder;">Black and White</asp:ListItem>
<asp:ListItem style="color: White; background-color: Black; font-weight: bolder;">Black and White Reverse</asp:ListItem>
<asp:ListItem style="color: Yellow; background-color: Black; font-weight: bolder;"
Value="Black and Yellow">Yellow and Black</asp:ListItem>
<asp:ListItem style="color: Black; background-color: Yellow; font-weight: bolder;"
Value="Black and Yellow">Yellow and Black Reverse</asp:ListItem>
<asp:ListItem style="color: Yellow; background-color: Blue; font-weight: bolder;"
Value="Blue and Yellow">Blue and Yellow</asp:ListItem>
<asp:ListItem style="color: Blue; background-color: Yellow; font-weight: bolder;"
Value="Blue and Yellow">Blue and Yellow Reverse</asp:ListItem>
...
...
</asp:DropDownList>
以下是母版页背后的代码:
Partial Class Site
Inherits System.Web.UI.MasterPage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim pageColor As String = ""
If Not Page.IsPostBack Then
Dim selectedTheme As String = Page.Theme
Dim preferredTheme As HttpCookie = Request.Cookies.Get("PreferredTheme")
If preferredTheme IsNot Nothing Then
selectedTheme = preferredTheme.Value
End If
If Not String.IsNullOrEmpty(selectedTheme) AndAlso DDL_SwitchTheme.Items.FindByValue(selectedTheme) IsNot Nothing Then
DDL_SwitchTheme.Items.FindByValue(selectedTheme).Selected = True
End If
End If
End Sub
Protected Sub DDL_SwitchTheme_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DDL_SwitchTheme.SelectedIndexChanged
Dim preferredTheme As HttpCookie = New HttpCookie("PreferredTheme")
preferredTheme.Expires = DateTime.Now.AddDays(7)
preferredTheme.Value = DDL_SwitchTheme.SelectedValue
Response.Cookies.Add(preferredTheme)
Response.Redirect(Request.Url.ToString())
End Sub
End Class
答案 0 :(得分:1)
真的没关系。当我第一次提出这个问题时,我忘记在我的下拉列表中添加一个重要属性,并勾选复选框 - AutoPostBack="True"
。因为我决定再次尝试编写可逆主题,所以我对主题名称没有第二个麻烦。
答案 1 :(得分:0)
它表示您从未将新选定的主题设置为代码中的页面。 尝试类似的东西:
Protected Sub DDL_SwitchTheme_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DDL_SwitchTheme.SelectedIndexChanged
Dim preferredTheme As HttpCookie = New HttpCookie("PreferredTheme")
preferredTheme.Expires = DateTime.Now.AddDays(7)
preferredTheme.Value = DDL_SwitchTheme.SelectedValue
' Set the new theme
Page.Theme=DDL_SwitchTheme.SelectedValue
Response.Cookies.Add(preferredTheme)
Response.Redirect(Request.Url.ToString())
End Sub