我正在创建一个带有几个高对比主题的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发布于 2014-06-20 21:28:02
这真的不重要。当我第一次问这个问题时,我忘了在下拉列表和复选框AutoPostBack="True"中添加一个重要的属性。自从我决定再次尝试编写可逆主题以来,我在主题名称方面还没有遇到任何麻烦。
发布于 2014-01-16 10:22:17
它会使您从未将新选定的主题设置为代码中的页。试着做这样的事:
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 Subhttps://stackoverflow.com/questions/21156265
复制相似问题