 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

November 3rd, 2011, 11:52 PM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 14
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Cant style elements after created the theme folders
hi
i have created 2 theme folders and put in all the related files and have done the code behind files also which makes it possible to dynamically change the theme using the drop-down list, but now when i try to style any elements on the page, the styles do not take effects, i tried changing both of the css files in both themes i have also tried changing a separate style sheet which i have put a reference to in the head section of the master page. nothing works, please help me as i was having so much fun with css before i implemented the themes in chapter 6.
|
|

November 4th, 2011, 03:35 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Does the page you're trying this on inherit the BasePage class?
If that's not the problem, can you post the code for the master page, your BasePage and the page you're trying this on?
Cheers,
Imar
|
|

November 4th, 2011, 10:10 AM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 14
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
_______________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Intranet : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
/*this implementation has to be in this file because the themelist drop list is implemented here */
//if the page is being rendered for the 1st time, !Page.IsPostBack == ispostback=false
if (!Page.IsPostBack)
{
string selectedTheme = Page.Theme;
HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
if (preferredTheme != null)
{
selectedTheme = preferredTheme.Value;
}
if (!string.IsNullOrEmpty(selectedTheme) && ThemeList.Items.FindByValue(selectedTheme) != null)
{
ThemeList.Items.FindByValue(selectedTheme).Selecte d = true;
}
}
}
protected void ThemeList_SelectedIndexChanged(object sender, EventArgs e)
{
HttpCookie preferredTheme = new HttpCookie("PreferredTheme");
preferredTheme.Expires = DateTime.Now.AddMonths(3);
preferredTheme.Value = ThemeList.SelectedValue;
Response.Cookies.Add(preferredTheme);
Response.Redirect(Request.Url.ToString());
}
}
________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for BasePage
/// </summary>
public class BasePage : System.Web.UI.Page
{
private void Page_PreInit(object sender, EventArgs e)
{
HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
if (preferredTheme != null)
{ Page.Theme = preferredTheme.Value; }
}
private void Page_PreRender(object sender, EventArgs e)
{
if (this.Title == "UntitledPage" || string.IsNullOrEmpty(this.Title))
{
throw new Exception("Page title cannot be \"Untitled Page\" or an empty string.");
}
}
public BasePage()
{ this.PreRender += new EventHandler(Page_PreRender);
this.PreInit += new EventHandler(Page_PreInit);
}
}
________________________________________________
could this be machine/cookie/cache problem,,,,i get different results on firefox and chrome, not correct results, but both browsers act diffidently to each other.
|
|

November 4th, 2011, 10:14 AM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 14
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Intranet.master.cs" Inherits="Intranet" %>
<!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 id="Head1" runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<div id="Container">
<form id="form1" runat="server">
<!--Header -->
<div class="Header">
</div>
<!-- create a SiteMapDataSource and then connect it to the asp:menu using a matching id -->
<div class="Menu"> <asp:SiteMapDataSource ID="AdminSystemSiteMap" runat="server" ShowStartingNode="false" />
<asp:Menu renderingmode="List" id="AdminSystemMenu" orientation="Vertical" runat="server" DataSourceID="AdminSystemSiteMap">
</asp:Menu>
<div class="ThemeSelector">Themes
<asp:DropDownList ID="ThemeList" runat="server" AutoPostBack="True"
onselectedindexchanged="ThemeList_SelectedIndexCha nged">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
</asp:DropDownList>
<!--content-->
<div class="Content"> <asp:ContentPlaceHolder id="cpMainContent" runat="server"></asp:ContentPlaceHolder>
</div>
<!-- footer
<div class="Footer">
<asp:Image Id="Image1" ImageUrl="~/Images/Header.gif" runat="server" Width="960" Height="174" AlternateText="Admin System"/>
</div>
-->
</form>
</div>
</body>
</html>
__________________________________________________ __
/*this is the test page created from Intranet.master and inherits basepage*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
_______________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Intranet : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
/*this implementation has to be in this file because the themelist drop list is implemented here */
//if the page is being rendered for the 1st time, !Page.IsPostBack == ispostback=false
if (!Page.IsPostBack)
{
string selectedTheme = Page.Theme;
HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
if (preferredTheme != null)
{
selectedTheme = preferredTheme.Value;
}
if (!string.IsNullOrEmpty(selectedTheme) && ThemeList.Items.FindByValue(selectedTheme) != null)
{
ThemeList.Items.FindByValue(selectedTheme).Selecte d = true;
}
}
}
protected void ThemeList_SelectedIndexChanged(object sender, EventArgs e)
{
HttpCookie preferredTheme = new HttpCookie("PreferredTheme");
preferredTheme.Expires = DateTime.Now.AddMonths(3);
preferredTheme.Value = ThemeList.SelectedValue;
Response.Cookies.Add(preferredTheme);
Response.Redirect(Request.Url.ToString());
}
}
________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for BasePage
/// </summary>
public class BasePage : System.Web.UI.Page
{
private void Page_PreInit(object sender, EventArgs e)
{
HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
if (preferredTheme != null)
{ Page.Theme = preferredTheme.Value; }
}
private void Page_PreRender(object sender, EventArgs e)
{
if (this.Title == "UntitledPage" || string.IsNullOrEmpty(this.Title))
{
throw new Exception("Page title cannot be \"Untitled Page\" or an empty string.");
}
}
public BasePage()
{ this.PreRender += new EventHandler(Page_PreRender);
this.PreInit += new EventHandler(Page_PreInit);
}
}
________________________________________________
could this be machine/cookie/cache problem,,,,i get different results on firefox and chrome, not correct results, but both browsers act diffidently to each other.
|
|

November 4th, 2011, 10:15 AM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 14
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
and the markup for the masterpage
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Intranet.master.cs" Inherits="Intranet" %>
<!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 id="Head1" runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<div id="Container">
<form id="form1" runat="server">
<!--Header -->
<div class="Header">
</div>
<!-- create a SiteMapDataSource and then connect it to the asp:menu using a matching id -->
<div class="Menu"> <asp:SiteMapDataSource ID="AdminSystemSiteMap" runat="server" ShowStartingNode="false" />
<asp:Menu renderingmode="List" id="AdminSystemMenu" orientation="Vertical" runat="server" DataSourceID="AdminSystemSiteMap">
</asp:Menu>
<div class="ThemeSelector">Themes
<asp:DropDownList ID="ThemeList" runat="server" AutoPostBack="True"
onselectedindexchanged="ThemeList_SelectedIndexCha nged">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
</asp:DropDownList>
<!--content-->
<div class="Content"> <asp:ContentPlaceHolder id="cpMainContent" runat="server"></asp:ContentPlaceHolder>
</div>
<!-- footer
<div class="Footer">
<asp:Image Id="Image1" ImageUrl="~/Images/Header.gif" runat="server" Width="960" Height="174" AlternateText="Admin System"/>
</div>
-->
</form>
</div>
</body>
</html>
|
|

November 4th, 2011, 10:56 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
A few things to check:
1. Are your themes really called red and Blue?
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
2. Did you modify the web.config file and disable the default theme?
3. Are you not getting any theme applied or do you see mixed results (e.g. multiple themes)
4. Try pressing Ctrl+F5 to force the browser to get the latest version of the files from the server.
Cheers,
Imar
|
|

November 4th, 2011, 11:29 AM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 14
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
im using the book to create my own project, hence the blue and red themes.
ctrl+f5 helped in firefox the themes apply and change according to the dropdown list, but
in google chrome the themes do not change when the drop down list is used.id put this down to be a browser specific problem.
thanks for your help.
|
|

November 4th, 2011, 11:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It works for me in Chrome on the official Planet Wrox site: http://aspnet4.planetwrox.com/default.aspx
So maybe this is a CSS issue?
Imar
|
|

November 4th, 2011, 12:24 PM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 14
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
im using some css 3 attributes, box shadow and radius, could that be the problem? also if you look at the image below i changed the attributes for the theme selector both in the red theme and the blue theme, but even after reloading the page using ctrl+f5 the theme selector portion in the red theme stays blue.
here is the css for the themes:
Red theme:
.ThemeSelector
{width:132px;
padding:0px;
background-color:#b60002;
border-left: 2px solid #ca0002;
border-top:1px solid #ca0002;
border-right: 1px solid #ca0002;
border-bottom: 3px solid #ca0002;
font-family: Arial, Helvetica, sans-serif;
color:White;
font-weight: bold;
font-size:12px;
text-indent:10px;
border-radius: 0px 0px 10px 10px;
}
Blue theme:
.ThemeSelector
{
width:132px;
padding:0px;
background-color:#0050b6;
border-left: 2px solid #0066ea;
border-top:1px solid #0066ea;
border-right: 1px solid #0066ea;
border-bottom: 3px solid #0066ea;
font-family: Arial, Helvetica, sans-serif;
color:White;
font-weight: bold;
font-size:12px;
text-indent:10px;
border-radius: 0px 0px 10px 10px;
}
http://img148.imageshack.us/img148/9...aaaaaaaala.jpg
|
|

November 4th, 2011, 12:40 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
What do you see when you view the browser's source? Do you see a diference between the browsers you're using?
Can't help much with this CSS without seeing your site online.
Cheers.
Imar
|
|
 |
|