Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : 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
 
Old May 8th, 2013, 05:11 PM
Registered User
 
Join Date: May 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Chapter6 Dynamic Themes

Hi there,

Just started learning this programming do-hicky stuff and it's fun!
Firstly, Imar, thanks for writing the book, awesome so far.

OK my problem is this:

I have placed the Drop-down menu for dynamic theme choice into it's own section:
Code:
<div id="ThemeSelect">
                <asp:DropDownList ID="ThemeList" runat="server" OnSelectedIndexChanged="ThemeList_SelectedIndexChanged">
                    <asp:ListItem>Default Orange</asp:ListItem>
                    <asp:ListItem>Asco Blue</asp:ListItem>
                </asp:DropDownList>
in the Frontend.master.cs:
Code:
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string selectedTheme = Page.Theme;
            HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
            if (preferredTheme != null)
            {
                selectedTheme = preferredTheme.Value;
            }
            if (!string.IsNullOrEmpty(selectedTheme))
            {
                ListItem item = ThemeList.Items.FindByValue(selectedTheme);
                if (item != null)
                {
                    item.Selected = true;
                }
            }
        } 
    }
When I run it I get an error, "NullReferenceException was unhandled by user code happening on Listitem item = ThemeList.Items.FindByValue(selectedTheme);

Object reference not set to an instance of an object.

I am being totally thick? I am creating my own site rather than building the example, but the code is so far pretty much the same. I ended up copying it from the download to make sure it was right, but still get this issue.

Any advice would simply ROCK!
 
Old May 9th, 2013, 04:15 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

That's really weird; I don't see anything wrong here. It seems that ThemeList itself is null. Can you confirm that using the debugger?

Could there be other code that messes with ThemeList? Another situation where ThemeList could be null is if you're using a Web Application Project (not a web site) and there is a mismatch between the markup (the .aspx part of the page) and the Designer file (that ends with Designer.cs. Could that be the case?

Otherwise, I don't really know yet what's going on; this code is programmed as defensively as it gets ;-)

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 9th, 2013, 02:25 PM
Registered User
 
Join Date: May 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Smile OK, so I'm a dumbass!

Imar, thanks for getting back to me on this. has been a little bit of head scratching on the go for this one, then I noticed that I had two aspx.cs files with identical referencing but to two different pages.

Firstly the frontend master, but also on the default.aspx.cs

So the Default was inheriting from the BasePage which was made with out the DDL so it was throwing an error because is was looking for it but not seeing it.

Resolution was this:

Recreated the Basepage and added all the code I wanted to replicate the site throughout as it is written, then added the DDL to the default.apsx only and removed all references from all other files, made sure it wasn't on any other .cs files applied the CSS and hey presto, this thing WROX (haha get it?)

so an ID10T error!

Sorry for wasiting your time, and thanks again for getting back to me.

Paddy.





Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter6 people.php saywhat BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 August 31st, 2012 08:20 AM
Chapter1-Chapter6 Kaf BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 0 March 31st, 2011 11:02 PM
chapter6.mysql mikezile BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 8 December 21st, 2007 07:34 AM
BugBase: Adding dynamic themes in Master Page rjd BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 13 November 28th, 2006 06:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.