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!