The name does not exist in the current context
Solution 1
In case other suggestions don't work, delete designer file, right click the markup file and click "convert to web application".
Solution 2
This error usually occours when you have copy pasted an aspx file. Please verify that your aspx is pointing to the correct cs file. Also check the names of the two files.
Other option is that there is something wrong with your designer file. If you want to Visual studio to regenerate your designer.cs file, you can go into design mode, make a small change and save the file.
Let me know if none of this works (90% of the time this issue is caused by this).
Solution 3
I had a similar issue when getting old VS2005 aspx/aspx.cs files into a new project in VS2013. I resolved this by creating a new web application, creating a new webform for each aspx page and copying the code for .aspx and .cs. Once copied I have to change the .cs files first line to use CodeBehind instead of CodeFile .
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="_Login" %>
TO
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="_Login" %>
I hope this helps someone else.
Related videos on Youtube
user2471435
Updated on September 16, 2022Comments
-
user2471435 about 1 year
I have the following HTML in an .aspx:
<div ID="divText" runat="server" style="position:absolute;top:60px; left:800px; width:600px; height:100px; z-index:2;font-size:200%"> </div>
Then in the code behind, IntelliSense finds the 'divText' but I get the compile error listed in the title
string productEdition = ConfigurationManager.AppSettings["Club"]; divText.InnerHtml = productEdition;
The compile error:
Error 3 The name 'divText' does not exist in the current context
The thing is the same EXACT html and code work in another file. We have tried everything. Any ideas?
-
gilly3 over 10 yearsAre you calling this from a static method?
-
-
Jace Rhea over 10 yearsIt's an ASP.NET server control. It should be an upper case ID.
-
Darin Dimitrov over 10 yearsWell actually casing of the id attribute doesn't matter at all in an aspx page. You could use
ID
,Id
,iD
or evenid
with exactly the same effect. -
user2471435 over 10 yearsThere is no designer file. Its a web site project.
-
Ali Shan over 4 yearsi am not able to solve this error, none of solutions provided by you are working
-
Ali Shan over 4 yearsi have the same issue but this solution does not works for me