0

This is specifically for Visual Studio 2015.

In my Site.master I have

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="~/Site.master.cs" Inherits="SiteMaster" %>

<asp:Literal ID="Literal1" runat="server" />

And in my Site.master.cs I have

Literal1.Text = "test";

In addition in Site.master.cs I have

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

using WebMatrix.Data;


public partial class SiteMaster : MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Literal1.Text = "test";
    }

And it won't build. I get the error:

error CS0103: The name 'Literal1' does not exist in the current context.

There is no designer file. I don't know how to get the designer file back for VS2015. I've tried several older suggestions from previous versions of VS. I'd like to get it to build whether I need a designer file or not.

Joshua Ginn
  • 109
  • 2
  • 11
  • Is it a web site project? Or a web application project? Did you manually remove a designer file? Are you using source code control? – mason Jan 20 '17 at 16:06
  • I'm using git source control. On my menu it says "Website," not project. – Joshua Ginn Jan 20 '17 at 16:09
  • In a website project, there would be no designer files. You probably need to show the @Page directive at the top of your ASPX and show the code for your class in your question. – mason Jan 20 '17 at 16:10
  • Ok, thanks. What's the difference between the website project and a web application project? Since it is a Master page it shows <%@ Master instead of <%@ Page – Joshua Ginn Jan 20 '17 at 16:13
  • Right, then include the @Master directive in your question. See [this question](http://stackoverflow.com/questions/398037/asp-net-web-site-or-asp-net-web-application) for the difference. – mason Jan 20 '17 at 16:14
  • Ok, I edited with @master. Any solution? – Joshua Ginn Jan 20 '17 at 16:19
  • You need to show the entire @Master directive in your question, and the corresponding class from your code behind. – mason Jan 20 '17 at 16:20
  • Is your Literal inside any other templated control, like a Repeater or GridView? Are other controls you reference by ID working? – mason Jan 20 '17 at 16:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/133658/discussion-between-josh-ginn-and-mason). – Joshua Ginn Jan 20 '17 at 16:35
  • No, it's just surrounded by html. A div tag – Joshua Ginn Jan 20 '17 at 16:42
  • @JoshGinn Could you change `CodeFile="~/Site.master.cs"` to `CodeBehind="Site.master.cs"` and see it makes any different? – Win Jan 20 '17 at 17:01
  • Thanks, @Win. I've tried that. It doesn't work. – Joshua Ginn Jan 20 '17 at 17:02
  • @JoshGinn Are you developing a new application or are you migrating old one to VS 2015? – Win Jan 20 '17 at 17:04
  • I started out with a new application. The – Joshua Ginn Jan 20 '17 at 17:06
  • @JoshGinn Could you show the steps how you create that ASP.Net Web Form Application? I'm curious why you have WebMatrix in your project. [WebMatrix](https://www.microsoft.com/web/webmatrix/) was replaced by Visual Studio Code. – Win Jan 20 '17 at 17:10
  • It's something we brought in for a data connection from an older project. However, I did create the project from scratch as a new VS2015 Web Forms application first. – Joshua Ginn Jan 20 '17 at 17:16
  • File> New Project > Web > ASP.NET Web Application > Web Forms – Joshua Ginn Jan 20 '17 at 17:19
  • @JoshGinn In that case, since it's a Project and not a Site, you should be using CodeBehind (instead of CodeFile) and you should have designer files. You can delete the page and recreate it and the system should create a designer file for you. – mason Jan 20 '17 at 17:44
  • @JoshGinn mason is correct. If you want to know how to regenerate designer, look at [here](http://stackoverflow.com/a/38103284/296861). – Win Jan 20 '17 at 18:07
  • I don't have that option. – Joshua Ginn Jan 23 '17 at 16:37

2 Answers2

0

Try to clean and rebuild your project obviously when the project is not running. Sometimes when your project is running visual studio cannot generate designer files properly. Try change the label Id or remove and re-insert it.

Majid Akbari
  • 200
  • 12
0

To solve this error I created a new master page. I deleted everything below the header and pasted everything below the header from the original (not including the original's header.)

Also, in the code behind I did not delete the class, but instead pasted the original functions into the new class.

Then on the pages that use the old master page I changed them to use the new master page.

Joshua Ginn
  • 109
  • 2
  • 11