Name does not exist in the current context

前端 未结 11 1651
时光说笑
时光说笑 2020-12-05 12:34

So, I\'m working on this project between my laptop and my desktop.

The project works on the laptop, but now having copied the updated source code onto the desktop, I

相关标签:
11条回答
  • 2020-12-05 13:29

    In case someone being a beginner who tried all of the above and still didn't manage to get the project to work. Check your namespace. In an instance where you copy code from one project to another and you forget to change the namespace of the project then it will also give you this error.

    Hope it helps someone.

    0 讨论(0)
  • 2020-12-05 13:31

    From the MSDN website:

    This error frequently occurs if you declare a variable in a loop or a try or if block and then attempt to access it from an enclosing code block or a separate code block.

    So declare the variable outside the block.

    0 讨论(0)
  • 2020-12-05 13:31

    Same issue happened with me when i mistakenly added some text in front of the top directive of the master page all the controls across all the page included in my project started showing, does not exist in the current context. After spending much time across the forum and self analysis, i found the mistakenly added text and removed but it does not solved the problem. Then i had to click on each error to open the associated page so that VS can load the page and recognize it, once the code was loaded in VS, error from those particular page started disappearing because VS recognized it. clicking on each error, loading each page in VS editor did the trick for me and you have to do it only once because later it will be automatically recognized by VS. I would say it is a Visual Studio Glitch.

    0 讨论(0)
  • 2020-12-05 13:32

    I also faced a similar issue. The reason was that I had the changes done in the .aspx page but not the designer page and hence I got the mentioned error. When the reference was created in the designer page I was able to build the solution.

    0 讨论(0)
  • 2020-12-05 13:37

    I came across a similar problem with a meta tag. In the designer.cs, the control was defined as:

    protected global::System.Web.UI.HtmlControl.HtmlGenericControl metatag;
    

    I had to move the definition to the .aspx.cs file and define as:

    protected global::System.Web.UI.HtmlControl.HtmlMeta metatag;
    
    0 讨论(0)
提交回复
热议问题