Label does not exist in current context on ASP.NET page

There are many questions with the same name as this one, but I have not found a solution.

MasterPage.master:

<div id="dateShow"> <asp:Label ID="lblDateShow" runat="server"></asp:Label> </div> 

MasterPage.master.cs:

 protected void Page_Load(object sender, EventArgs e) { lblDateShow.Text = DateTime.Now.ToShortDateString(); } 

This happens during construction and shows me an error, but if I run without a building (before starting β†’ no assembly), it will show me the date. This only happens on the main page with all the controls that I want to add, on other pages everything works fine. What could be the problem?

Error message:

Error 1 The name "lblDateShow" does not exist in the current context

Long mention:

Warning 2 The type "MasterPage" in "c: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Temporary ASP.NET Files \ thegame \ 6da1e5d1 \ 9152b07 \ App_Web_tmu2ya5i.4.cs" conflicts with the imported type "MasterPage" in " c: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Temporary ASP.NET files \ thegame \ 6da1e5d1 \ 9152b07 \ App_Web_masterpage.master.cdcab7d2.k9aa16y-.dll '. Using the type defined in' c: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Temporary ASP.NET Files \ thegame \ 6da1e5d1 \ 9152b07 \ App_Web_tmu2ya5i.4.cs'. C: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Temporary ASP.NET Files \ thegame \ 6da1e5d1 \ 9152b07 \ App_Web_tmu2ya5i.4.cs

I tried to delete Temp files, did not help ..

UPD I solved this problem. I had another masterpage2.master, and it somehow dealt with all the problems. When I created a shortcut or other control, it was declared on the second main page, I do not know how this can be))

+6
source share
3 answers

This happened to me, and I spent several days before discovering that I had another page with the same code (CodeFile = "PageName.aspx.cs") that did not have a control identifier. I just deleted it and the problem was removed together.

+8
source

If lblDateShow is in the layout of the main page, but it does not seem to exist in the code file, then this is most likely a problem with the designer.cs file for your main page. Is lblDateShow there? If not, you will need to restore the designer file or add the shortcut manually.

+2
source

Try putting it in the correct namespace. That was my problem

+2
source

Source: https://habr.com/ru/post/891171/


All Articles