Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird Error on Visual Studio - "you could use the navigation bar to switch context"

I have been trying to link a a web form to be a able to access a variable in the master page. I did this before it worked. But now when I do it I get an error.

The code in Site.Master

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

The code in Site.Master.cs

public partial class Site : System.Web.UI.MasterPage
{
    public string hi = "";

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

The code in WebForm1.aspx:

<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1" %>
<%@ MasterType VirtualPath="~/Site.master" %>

The Code in WebForm1.aspx.cs

public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
     {
         Master.hi="new"
     }
}

When I hover over the hi, I get this message

Error in Visual Studio - "You can use navigation bar to switch contexts

Here is another image Screenshot

If you guys could help me it will really be great

like image 473
MosesAronov Avatar asked Dec 10 '15 03:12

MosesAronov


2 Answers

I had this same problem in an MVC application so the WebForm-CodeFile-CodeBehind suggestion didn't really apply.

However, I realized the new classes that I created had their "Build Action" set to "Content". Once I changed this to "Compile", everything started working again.

like image 117
BLynn Avatar answered Sep 23 '22 06:09

BLynn


In your WebForm1.aspx, try changing CodeFile to CodeBehind. That's what worked for me.

like image 28
Brendan L Avatar answered Sep 22 '22 06:09

Brendan L