 |
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
|
|
|
|
|

December 17th, 2013, 05:18 PM
|
|
Registered User
|
|
Join Date: Dec 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chap 6 - Dynamically changing Themes
OK. Going nuts here. I've double and triple checked my code to no avail. Still cannot get it to work. A second set of eyes would be helpful. I've deleted cookies and tried all browsers. No luck. Nothing happens. Page simply posts to itself again.
Help??? Thanks!
Web Config:
<pages theme="Monochrome"></pages>
BasePage.cs:
private void Page_PreInit(object sender, EventArgs e)
{
HttpCookie preferredTheme = Request.Cookies.Get("UserPreferredTheme");
if (preferredTheme != null)
{ Page.Theme = preferredTheme.Value; }
}
public BasePage()
{
this.PreRender += new EventHandler(Page_PreRender);
this.PreInit += new EventHandler(Page_PreInit);
}
FrontEnd.master:
<div id="SideBar">Select a Theme<br />
<asp:DropDownList ID="ThemeList" runat="server" AutoPostBack="True"
onselectedindexchanged="ThemeList_SelectedIndexCha nged">
<asp:ListItem>Monochrome</asp:ListItem>
<asp:ListItem>DarkGrey</asp:ListItem>
</asp:DropDownList>
</div>
FrontEnd.master.cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string selectedTheme = Page.Theme;
HttpCookie preferredTheme = Request.Cookies.Get("UserPreferredTheme");
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("UserPreferredTheme");
preferredTheme.Expires = DateTime.Now.AddMonths(3);
preferredTheme.Value = ThemeList.SelectedValue;
Response.Cookies.Add(preferredTheme);
Response.Redirect(Request.Url.ToString());
}
|
|

December 17th, 2013, 05:40 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Is the page you're testing this on inheriting BasePage? If not, the theme will never be applied.
If you post code here, can you please paste it in Notepad first and then use the Code (#) button on the toolbar to mark your code as code? That makes it easier to read.
Cheers,
Imar
|
|

December 17th, 2013, 06:18 PM
|
|
Registered User
|
|
Join Date: Apr 2013
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
I revall similar issues from time to time!
I've been bitten by these matters, you check the code to the displayed code and it matches, In the end I copied the page from the downloaded source code and it worked.. I'll never know where I went wrong but I tend to re-do an example on my own demo websites to ensure I didn't do anything wrong!.
I think there's some tiny bugs within the VWD 2010, sometimes you just have to go back and press space on the code to get Intellisense to guide you in the right direction. (Ive recently upgraded to 2013 and ive finally managed to get the code to load up again!.

|
|

December 17th, 2013, 06:35 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
>> I think there's some tiny bugs within the VWD 2010
I am sure there are ;-) Be sure to report them on Microsoft's Connect site so they can be fixed, in 2013 or in later releases.
Cheers,
Imar
|
|

December 18th, 2013, 10:16 AM
|
|
Registered User
|
|
Join Date: Dec 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Imar
Hi there,
Is the page you're testing this on inheriting BasePage? If not, the theme will never be applied.
If you post code here, can you please paste it in Notepad first and then use the Code (#) button on the toolbar to mark your code as code? That makes it easier to read.
Cheers,
Imar
|
That was the issue! Thanks. Good catch!
|
|

January 7th, 2014, 02:45 PM
|
|
Registered User
|
|
Join Date: Apr 2013
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Imar
>> I think there's some tiny bugs within the VWD 2010
I am sure there are ;-) Be sure to report them on Microsoft's Connect site so they can be fixed, in 2013 or in later releases.
Cheers,
Imar
|
 whoops , caught by the teacher!, I meant to say theres a few behavioural differences to 2013 (especially database designer)
base page, now I know where I was going wrong!, thanks
|
|
 |
|