Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > BOOK: Beginning ASP.NET 4.5 : in C# and VB
|
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 September 4th, 2014, 11:06 AM
Registered User
 
Join Date: Sep 2014
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Between Frontend.master & master.cs - items do not exist in current context

Hi,

Great book and I'm sure this is an error on my behalf, but it's driving me crazy trying to figure out what's going on. When I build the web site, I keep getting three errors stating that the 'ThemeList', 'Menu1' & 'TreeView1' do not exist in the current context....

Those controls are clearly defined in Frontend.master and the errors are showing up in the Frontend.master.cs file. I will attach code of both below.

Thanks in advance for your help!
Damon

Here is the code for Frontend.master:

Code:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Frontend.master.cs" Inherits="MasterPages_Frontend" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  <asp:ContentPlaceHolder ID="head" runat="server">
  </asp:ContentPlaceHolder>
  <script src="/Scripts/modernizr-2.6.2.js"></script>
</head>
<body>
  <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
    <div id="PageWrapper">
      <header><a href="/"></a></header>
      <nav>
        <asp:Menu ID="Menu1" runat="server" CssClass="MainMenu" DataSourceID="SiteMapDataSource1" Orientation="Horizontal" StaticEnableDefaultPopOutImage="False"></asp:Menu>
        <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" ShowExpandCollapse="False">
          <LevelStyles>
            <asp:TreeNodeStyle CssClass="FirstLevelMenuItems" />
          </LevelStyles>
        </asp:TreeView>
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />
      </nav>
      <section id="MainContent">
        <asp:SiteMapPath ID="SiteMapPath1" runat="server"></asp:SiteMapPath>
        <br />
        <br />
        <asp:ContentPlaceHolder ID="cpMainContent" runat="server">
        </asp:ContentPlaceHolder>
      </section>
      <aside id="Sidebar">
        Select a theme<br />
        <asp:DropDownList ID="ThemeList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ThemeList_SelectedIndexChanged">
          <asp:ListItem>Monochrome</asp:ListItem>
          <asp:ListItem>DarkGrey</asp:ListItem>
        </asp:DropDownList>
        <br />
        <br />
        <Wrox:Banner ID="Banner1" runat="server" DisplayDirection="Vertical" />
        <br />
      </aside>
      <footer>Footer Goes Here</footer>
    </div>
  </form>
</body>
</html>
This is the code for Frontend.master.cs:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MasterPages_Frontend : System.Web.UI.MasterPage
{
  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;
        }
      }
    }
    switch (Page.Theme.ToLower())
    {
      case "darkgrey":
        Menu1.Visible = false;
        TreeView1.Visible = true;
        break;
      default:
        Menu1.Visible = true;
        TreeView1.Visible = false;
        break;
    }
  }

  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());
  }
}
Here are the error messages from VS:
Code:
Error	1	The name 'ThemeList' does not exist in the current context	T:\Damon\Wrox\BegASPNET\Site\App_Code\Frontend.master.cs	22	25	Site
Error	2	The name 'Menu1' does not exist in the current context	T:\Damon\Wrox\BegASPNET\Site\App_Code\Frontend.master.cs	32	9	Site
Error	3	The name 'TreeView1' does not exist in the current context	T:\Damon\Wrox\BegASPNET\Site\App_Code\Frontend.master.cs	33	9	Site
Error	4	The name 'Menu1' does not exist in the current context	T:\Damon\Wrox\BegASPNET\Site\App_Code\Frontend.master.cs	36	9	Site
Error	5	The name 'TreeView1' does not exist in the current context	T:\Damon\Wrox\BegASPNET\Site\App_Code\Frontend.master.cs	37	9	Site
Error	6	The name 'ThemeList' does not exist in the current context	T:\Damon\Wrox\BegASPNET\Site\App_Code\Frontend.master.cs	46	28	Site

Last edited by damoncombs; September 4th, 2014 at 12:01 PM.. Reason: Adding the error messages from VS
 
Old September 4th, 2014, 05:58 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

That's odd. Your code looks fine; I just copied and pasted it in my site and there are no errors.

Could there be another build error that prevents the site from compiling? When you look at the site in File Explorer in Windows, do you see any files that shouldn't be there (such as a copy of the master)?

If you can't solve it, send me a zipped version of the site and I'll take a look. You find my e-mail address in the introduction of the book.

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 September 4th, 2014, 06:00 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Oh, I just noticed this:

>> \Wrox\BegASPNET\Site\App_Code\Frontend.master.cs

Somehow your master page or code file ended up in App_Code. Both should be in the MasterPages folder.

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!
The Following User Says Thank You to Imar For This Useful Post:
damoncombs (September 5th, 2014)
 
Old September 5th, 2014, 10:19 AM
Registered User
 
Join Date: Sep 2014
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Solved

That was it! Not sure how or why the .cs file ended up in there....

It's amazing how this site is so helpful and I don't think it would work as well as it does without your involvement, Imar. You, Sir, do a great service to everyone who participates here.

Thanks again for your time,
Damon
 
Old September 5th, 2014, 11:02 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Damon,

You're very welcome. Glad to hear the problem is now fixed.

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
The name 'ErrorMessage' does not exist in the current context ken evans BOOK: Beginning ASP.NET 4 : in C# and VB 9 November 3rd, 2010 06:48 AM
The name 'ErrorMessage' does not exist in the current context ken evans BOOK: Beginning ASP.NET 4 : in C# and VB 0 November 2nd, 2010 11:07 AM
The name 'Request' does not exist in the current context janilane BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 July 13th, 2010 05:46 PM
The name 'partOneStep' does not exist in the current context pallone ASP.NET 3.5 Basics 11 March 4th, 2009 05:30 AM
The name 'txtOperande1' does not exist in the current context stevemcd999 BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 3 February 25th, 2009 11:58 PM





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