Asked by:
Skins not changing from dropdown box on homepage

Question
-
User1673739617 posted
Hi,
I'm using the Personal Starter Kit with ASP.Net 2.0.
I am unable to change the Skin colour from the drop-down box on my homepage:
http://www.birchdalegardens.com/
as you can see its not generating any error, but at the same time it's not changing the Skin.
I have the APP_Themes folder with all the required files in it, and have the MASTER Pages folder as well, but still no joy...
[b]Do I need to add something to my web.config (see below)[/b]
can anyone suggest how I can fix it?
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
<!-- Connection for SQL 2005 Express -->
<remove name="Personal"/>
<add name="Personal" connectionString="Data Source=.....;uid=...;password='....';Initial catalog=....." providerName="System.Data.SqlClient"/>
<!-- Connection for SQL Server 2005 -->
<!--<add name="Personal" connectionString="Server=(Local);Integrated Security=True;database=Personal" providerName="System.Data.SqlClient"/>-->
<remove name="LocalSqlServer"/>
<!-- Connection for SQL 2005 Express -->
<add name="LocalSqlServer" connectionString="Data Source=......;uid=.....;password='.....';Initial catalog=......." providerName="System.Data.SqlClient"/>
<!-- Connection for SQL Server 2005 -->
<!--<add name="LocalSqlServer" connectionString="Server=(Local);Integrated Security=True;database=Personal" providerName="System.Data.SqlClient"/>-->
</connectionStrings>
<system.web>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Specialized"/>
<add namespace="System.Configuration"/>
<add namespace="System.Text"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Caching"/>
<add namespace="System.Web.SessionState"/>
<add namespace="System.Web.Security"/>
<add namespace="System.Web.Profile"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.WebParts"/>
<add namespace="System.Web.UI.HtmlControls"/>
<add namespace="System.Data"/>
<add namespace="System.Data.Sql"/>
<add namespace="System.Data.SqlClient"/>
</namespaces>
</pages>
<httpHandlers>
<add type="PeterKellner.Utils.CaptchaTypeHandler" verb="GET" path="CaptchaType.ashx"/>
</httpHandlers>
<customErrors mode="Off"/>
<compilation debug="true">
<assemblies>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>
<authentication mode="Forms">
<forms loginUrl="Login.aspx" protection="Validation" timeout="50000" />
</authentication>
<authorization>
<allow users="*"/>
</authorization>
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
<membership>
<providers>
<add connectionStringName="LocalSqlServer" enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/"
requiresUniqueEmail="true" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0"
passwordStrengthRegularExpression="" passwordFormat="Hashed"
passwordAttemptWindow="10" name="DefaultMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add connectionStringName="LocalSqlServer" enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="false"
applicationName="/" requiresUniqueEmail="true" minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0" passwordStrengthRegularExpression=""
passwordFormat="Hashed" passwordAttemptWindow="10" name="AdminMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>
<profile>
<properties>
<add name="FirstName"/>
<add name="LastName"/>
<add name="Website"/>
<add name="PasswordAnswer"/>
</properties>
</profile>
<roleManager enabled="true" />
<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
<providers>
<add name="XmlSiteMapProvider" description="SiteMap provider which reads in .sitemap XML files." type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="true"/>
</providers>
</siteMap>
</system.web>
<system.net>
<mailSettings>
<smtp from="youname@yourdomain.net">
<network host="smtp.yourdomain.net" userName="yourusername" password="yourpassword" />
</smtp>
</mailSettings>
</system.net>
<location path="~/Albums/4/61.jpg">
<system.web>
<authorization>
<allow roles="Family"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
<!--<location path="Downloads">
<system.web>
<authorization>
<allow roles="Administrators,Registered Users"/>
<deny users="*"/>
</authorization>
</system.web>
</location>-->
<location path="App_Themes">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="Admin">
<system.web>
<authorization>
<allow roles="Administrators"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
<appSettings>
<!-- The Album Path needs to be in the form of "~/FolderName"
When the application creates an album to store photos in, it will create the album inside the folder
specified here. -->
<add key="AlbumsFolder" value="~/Albums" />
<!-- This key specifies the folder to use for Uploads. At this time there is at least one stored procedure that
still references the upload folder statically. Once that is changed you would be able to specify any folder
here that the application should use for working with Uploaded photos that have not been imported to an album.-->
<add key="UploadFolder" value="~/Upload" />
<!-- This key defines what role a new user will be assigned to by default. If set to blank, the user will be
created but not assigned to any roles. The user would then need to be assigned to a role by the administrator
before they would have an special access to the website.-->
<add key="DefaultRoleForNewUser" value="Registered Users"/>
<!-- This key defines the theme that will be used on the admin pages. I created this setting because it will
reduce the time it takes to create a new theme if you don't have to create all new buttons and css to go with
administration pages. I found it easier just to have the admin sections use the White theme. If left blank the
admin pages will use whatever theme is selected for the site. -->
<add key="AdminTheme" value="White"/>
<!-- This key defines the user account to be notified for all site notification. Guestbook entry, blog comments, new user, etc. -->
<add key="NotifyAccount" value="Admin"/>
<!-- This key defines the email address to send errors to. It is defined here in case the error is generated
as a result of a database connection in which we would not be able to retrieve the admin email -->
<add key="AdminEmail" value="youremail@yourdomain.net"/>
</appSettings>
</configuration>
Wednesday, September 3, 2008 2:08 PM
All replies
-
User986106991 posted
Hello Ricky,
You can change the theme of your web page at run time by adding following code in Page_PreInit event:
Page.Theme = ddlThemes.Text; //Make sure that you re-set theme only in PreInit event.
Also, i visited your web-site, and noticed that value in Skin DropDownList is not getting re-set,
whatever we select, it will again show "default" as selected after post-back.
Please re-check the code you have written on Page_Load of your content as well as master page.Post your code, if above does not solve your problem.
Good luck!Thursday, September 4, 2008 6:49 PM -
User1673739617 posted
Hi, On what page would the pre_init event above go? Can you send me this block of code, to change the theme at run-time?
Still can't get it to work. I attach 2 lots of code below 1) page_load event in default.aspx and 2) master pages default theme code
here is my page_load event code in default.aspx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
Dim objSiteContent As SiteContent
Dim myList As Generic.List(Of SiteContent) = SiteContentManager.GetSiteContent()
Dim objSettings As SiteSettings = SiteSettingsManager.GetSiteSettings()
For Each objSiteContent In myList
With objSiteContent
Select Case .ContentName.ToUpper
Case "WELCOME"
If .IsVisible = 1 Then
lblWelcomeText.Text = .ContentText
lblWelcomeTitle.Text = .ContentTitle
End If
Case "WHATSNEW"
If .IsVisible = 1 Then
lblWhatsNewTitle.Text = .ContentTitle
lblWhatsNewText.Text = .ContentText
End If
Case "LATESTNEWS"
If .IsVisible = 1 Then
lblLatestNewsTitle.Text = .ContentTitle
lblLatestNewsText.Text = .ContentText
End If
End Select
End With
Next
Session("Theme") = objSettings.ThemeName
If CBool(Session.Item("EnableUserThemes")) = True Then
'Portal Specific Reference
mstrTheme = objSettings.ThemeName
drpThemes.DataSource = Globals.GetThemesList()
drpThemes.DataBind()
drpThemes.SelectedValue = mstrTheme
drpThemes.Visible = True
lblSelectSkin.Visible = True
Else
drpThemes.Visible = False
lblSelectSkin.Visible = False
End If
Else
mstrTheme = CStr(Session("Theme"))
End If
End Sub
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Dim blnAdminAuth As Boolean = Roles.IsUserInRole("Administrators")
ibtnEditWelcome.Visible = blnAdminAuth
ibtnEditWhatsNew.Visible = blnAdminAuth
ibtnEditLatestNews.Visible = blnAdminAuth
ibtnBlogEntryAdd.Visible = blnAdminAuth
End Sub
Protected Sub drpThemes_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles drpThemes.SelectedIndexChanged
SiteSettingsManager.UpdateSiteSettings(1, drpThemes.SelectedItem.Value)
Response.Redirect("Default.aspx")
End Sub
Public Sub Randomize(ByVal sender As Object, ByVal e As EventArgs)
Dim r As Random = New Random
FormView1.PageIndex = r.Next(FormView1.PageCount)
End Sub
End Classhere is my code for my master pages default theme
Partial Class Default_Master
Inherits System.Web.UI.MasterPage
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
If Page.IsPostBack = False Then
Page.Title = Session.Item("SitePageTitle")
lblSiteName.Text = Session.Item("SiteName")
lblSiteSlogan.Text = Session.Item("SiteSlogan")
lblCopyrightCredits.Text = Session.Item("CopyrightCredits")
End If
Dim metaTag As New HtmlMeta
Dim HeadTag As HtmlHead = CType(Page.Header, HtmlHead)
metaTag.Attributes.Add("name", "description")
metaTag.Attributes.Add("content", CStr(Session.Item("MetaDescription")))
HeadTag.Controls.Add(metaTag)
metaTag = New HtmlMeta
metaTag.Attributes.Add("name", "keywords")
metaTag.Attributes.Add("content", CStr(Session.Item("MetaKeywords")))
HeadTag.Controls.Add(metaTag)
End Sub
Protected Sub menua_MenuItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles menua.MenuItemDataBound
' Check for the Register menu item
If e.Item.Text = "Register" Then
' Set the visibility of the Register menu item based on site settings from db
If (CBool(Session.Item("EnableRegistration")) = False) Or (Context.User.Identity.IsAuthenticated = True) Then
e.Item.Parent.ChildItems.Remove(e.Item)
End If
End If
End Sub
Protected Sub menub_MenuItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles menub.MenuItemDataBound
' Check for the Register menu item
If e.Item.Text = "Register" Then
' Set the visibility of the Register menu item based on site settings from db
If CBool(Session.Item("EnableRegistration")) = False Then
e.Item.Parent.ChildItems.Remove(e.Item)
End If
End If
End Sub
Protected Sub menua_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles menua.MenuItemClick
End Sub
End Class
Friday, September 5, 2008 8:55 AM -
User986106991 posted
one question:
Have you added Themes dropdownlist on your content page or master page?
I feel it should be added on master page, if you have not done that.Friday, September 5, 2008 9:19 AM -
User1673739617 posted
On what page should i be adding the themes dropdown list?
there is no master page(s) in the root of my website, all master pages are saved in a folder called "master pages"...
here is the code for my default.master page in the "master pages" folder:
<%@ Master Language="VB" CodeFile="Default.master.vb" Inherits="Default_Master" %>
<!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" xml:lang="en" >
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript" src="../Lytebox/lytebox.js"></script>
<link rel="stylesheet" href="../Lytebox/lytebox.css" type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title="Jeremy Wadsworth's Blog" href="http://www.jeremywadsworth.com/RSSFeed.aspx" />
</head>
<body>
<form id="form1" runat="server">
<div class="header">
<table id="SiteNameContainer" align="left" cellpadding="5" cellspacing="0" border="0">
<tr>
<td valign="top" align="left">
<asp:Label ID="lblSiteName" CssClass="SiteName" runat="server" /></td>
</tr>
<tr>
<td valign="top" align="left">
<asp:Label ID="lblSiteSlogan" CssClass="SiteSlogan" runat="server" /></td>
</tr>
</table>
<asp:menu id="menua" runat="server"
datasourceid="SiteMapDataSource1"
cssclass="menua"
orientation="Horizontal"
maximumdynamicdisplaylevels="0"
skiplinktext=""
staticdisplaylevels="2" />
<div class="nav">
<%--<asp:SiteMapPath id="SiteMapPath1" runat="Server" PathSeparator=" > " RenderCurrentNodeAsLink="true" />
| --%>
<asp:loginview id="LoginArea" runat="server">
<LoggedInTemplate>
<asp:loginname id="LoginName1" runat="server" formatstring="Logged in as {0}! | " /><asp:HyperLink ID="HyperLink1" runat="server" Text="My Profile" NavigateUrl="~/MyProfile.aspx" /> |
</LoggedInTemplate>
</asp:loginview>
<asp:LoginStatus ID="LoginStatus1" Runat="server" LogoutPageUrl="~/Default.aspx" LogoutAction="Redirect" />
</div>
</div>
<asp:contentplaceholder id="Main" runat="server" />
<div class="footerbg">
<div class="footer">
<asp:menu id="menub" runat="server"
datasourceid="SiteMapDataSource1"
cssclass="menub"
orientation="Horizontal"
maximumdynamicdisplaylevels="0"
skiplinktext=""
staticdisplaylevels="2" />
<asp:Label ID="lblCopyrightCredits" runat="server" />
</div>
</div>
<asp:sitemapdatasource id="SiteMapDataSource1" runat="server" startingnodeoffset="0" />
</form>
</body>
</html>thanks
Friday, September 5, 2008 10:04 AM -
User986106991 posted
Add Themes dropdownlist to the master page - that you are using as a template for all other web-pages.
Is there any reason to have multiple master pages in your web-site?
I am working on some code and will soon post code for dynamic - application level theme changes.Good Luck!
Friday, September 5, 2008 10:39 AM -
User1673739617 posted
Sorry, i'm fairly new to asp.net. The personal starter kit, im using is from a download on the jeremy wadsworth website, in this example there are multiplemaster pages within a master pages folder...
I look forward to seeing and testing your code...
Friday, September 5, 2008 12:59 PM -
User595806616 posted
The following code should fix the problem. This code replace everything in the Global.asax file.
1 <%@ Application Language="VB" %> 2 3 <script runat="server"> 4 5 Sub Application_Start(ByVal sender As [Object], ByVal e As EventArgs) 6 AddHandler SiteMap.SiteMapResolve, AddressOf Me.AppendQueryString 7 If (Roles.RoleExists("Administrators") = False) Then 8 Roles.CreateRole("Administrators") 9 End If 10 If (Roles.RoleExists("Friends") = False) Then 11 Roles.CreateRole("Friends") 12 End If 13 14 ' Set our user count to 0 when we start the server 15 Application("ActiveUsers") = 0 16 End Sub 17 18 Sub Session_OnStart(ByVal sender As [Object], ByVal e As EventArgs) 19 Session.Timeout = 10 20 Session("Start") = Now 21 Application.Lock() 22 Application("ActiveUsers") = CInt(Application("ActiveUsers")) + 1 23 Application.UnLock() 24 25 'SiteSettingsManager.UpdateSiteSettings(1, "Default") 26 End Sub 27 28 Sub Session_OnEnd(ByVal sender As [Object], ByVal e As EventArgs) 29 Application.Lock() 30 Application("ActiveUsers") = CInt(Application("ActiveUsers")) - 1 31 Application.UnLock() 32 End Sub 33 34 Function AppendQueryString(ByVal o As [Object], ByVal e As SiteMapResolveEventArgs) As SiteMapNode 35 If (Not (SiteMap.CurrentNode) Is Nothing) Then 36 Dim temp As SiteMapNode 37 temp = SiteMap.CurrentNode.Clone(True) 38 Dim u As Uri = New Uri(e.Context.Request.Url.ToString) 39 temp.Url = (temp.Url + u.Query) 40 If (Not (temp.ParentNode) Is Nothing) Then 41 temp.ParentNode.Url = (temp.ParentNode.Url + u.Query) 42 End If 43 Return temp 44 Else 45 Return Nothing 46 End If 47 End Function 48 49 </script>
Friday, September 5, 2008 2:16 PM -
User986106991 posted
Hello Ricky,
namespace MyWebSite
I hope that last post by Jeremy Wadsworth would have solved your problem.
But in case you are still stuck, then I am here with some sample code [:)]
I will start with few quick notes about Themes and Skins:
- Themes allows us to change the appearance of web-pages and
different themes in a web-site helps user to select a theme of his own personal choice.
- During development, we can apply themes at three different levels:
1. Web-site level (setting required in web.config file)
2. Page Level (setting required in <%@ Page … %> directive)
3. Control Level (required to set SkinId property of the control)
For further reading about this, you can follow this link:
http://www.code-magazin.de/article.aspx?quickid=0709061&page=5
Now, my post perhaps will not address your sample application problem
but for sure, it will help you to understand how to : Change Web-Site Theme at run-time in ASP.Net 2.0
Before we jump onto steps, note that in my sample code,
Themes DropdownList control is in .master page that I am using as a template for my web-pages.
STEP# 1:
Create a class, BasePage.cs in App_Code folder and inherit it from System.Web.UI.Page
Following is the code for this class:
{
/// <summary>
/// This class will serve as base class for all the web pages in my web-site.
/// </summary>
public class BasePage : System.Web.UI.Page
{
public BasePage()
{
}
protected void Page_PreInit(Object sender, EventArgs e)
{
if (Session["Theme"] != null)
{
//Create object of DropDownList control available in Master Page,
//you can access the Master page by using Page.Master
DropDownList ddlThemes = (DropDownList)Page.Master.FindControl("ddlThemes");
ddlThemes.SelectedValue = Session["Theme"].ToString();
//Re-set Page Theme with Session Variable
this.Theme = Session["Theme"].ToString();
}
else
{
//Create Session variable, it should contain the theme name, that you want should be selected by default
//Here, i wanted my theme "Caribbean Sun" to show by default
Session["Theme"] = "Caribbean Sun";
this.Theme = "Caribbean Sun";
}
}
}
}
All the content web-pages in web-site will inherit from this class as shown below:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
public partial class SayHello : MyWebSite.BasePage
//Changes in Master Page
{
//class body
}
The reason I have created BasePage class is to avoid code duplication and take advantage of inheritance.
If I don’t use this approach, then code written in Page_PreInit event of BasePage class has to be copied on all the web-pages of my web-site.
STEP# 2:
Next step is to make changes in master page that you will be using as template for other web-pages.
You need to make changes in Page_Load event and ddlThemes_SelectedIndexChanged event.
protected void Page_Load(object sender, EventArgs e)<o:p></o:p>
{
if (!IsPostBack)
{
this.ddlThemes.SelectedValue = Session["Theme"].ToString() ;
}
}
<o:p></o:p>
protected void ddlThemes_SelectedIndexChanged(object sender, EventArgs e)<o:p></o:p>{
Session["Theme"] = this.ddlThemes.SelectedValue;
Response.Redirect(Request.Url.ToString());
}
STEP# 3:
Change the content Web-Pages to inherit from BasePage class, for example, as:
public partial class SayHello : MyWebSite.BasePage
{
…
}
I hope this will help you to resolve your problem.
In case you find any problem, please post back.
Good Luck!
Friday, September 5, 2008 8:23 PM -
User1673739617 posted
hi,
NO, the last post from Jeremy did not solve my problem. He gave me an updated global.asax file to upload but i'm still having the same issues...
Will your post above, actually solve my issue, of the skins changing dynamically?my current global.asax code is below, do you see any problems with it?
<%@ Application Language="VB" %>
<script runat="server">
Sub Application_Start(ByVal sender As [Object], ByVal e As EventArgs)
AddHandler SiteMap.SiteMapResolve, AddressOf Me.AppendQueryString
If (Roles.RoleExists("Administrators") = False) Then
Roles.CreateRole("Administrators")
End If
If (Roles.RoleExists("Friends") = False) Then
Roles.CreateRole("Friends")
End If
' Set our user count to 0 when we start the server
Application("ActiveUsers") = 0
End Sub
Sub Session_OnStart(ByVal sender As [Object], ByVal e As EventArgs)
Session.Timeout = 10
Session("Start") = Now
Application.Lock()
Application("ActiveUsers") = CInt(Application("ActiveUsers")) + 1
Application.UnLock()
End Sub
Sub Session_OnEnd(ByVal sender As [Object], ByVal e As EventArgs)
Application.Lock()
Application("ActiveUsers") = CInt(Application("ActiveUsers")) - 1
Application.UnLock()
End Sub
Function AppendQueryString(ByVal o As [Object], ByVal e As SiteMapResolveEventArgs) As SiteMapNode
If (Not (SiteMap.CurrentNode) Is Nothing) Then
Dim temp As SiteMapNode
temp = SiteMap.CurrentNode.Clone(True)
Dim u As Uri = New Uri(e.Context.Request.Url.ToString)
temp.Url = (temp.Url + u.Query)
If (Not (temp.ParentNode) Is Nothing) Then
temp.ParentNode.Url = (temp.ParentNode.Url + u.Query)
End If
Return temp
Else
Return Nothing
End If
End Function
</script>
thanks,
ricky
Saturday, September 6, 2008 8:10 AM -
User986106991 posted
Ricky,
Actually i do not have any idea about multiple master pages in your sample application that you are working on.
I think understanding the concept behind mutiple master pages there and
first having a walk-over some Themes and Skins basics from the link:
http://www.code-magazin.de/article.aspx?quickid=0709061&page=5 should surely help you.
After that you can go over my previous post to Change Web-Site Theme at run-time in ASP.Net 2.0
Good Luck!Sunday, September 7, 2008 6:01 PM