Label does not exist in current context on ASP.NET page
There are many questions with same name as this one, but I haven't found 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();
}
It happens on building and show me the error, but if I run without building (before run-->no build) it shows me the date. It happens only in master page with all controls that I want to add, on other pages all work fine. What could be the problem?
Error Message is:
Error 1 The name 'lblDateShow' does not exist in the current context
Long discription:
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:\Windo开发者_JAVA技巧ws\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, didn't help..
UPD I solved that problem. I Had another masterpage2.master and somehow he did all the problems. When I created label or other control, he was declared in second master page, I don't know how can it be))
It happend with me and I took some days until discovery that I had one more page with the same code behind (CodeFile="PageName.aspx.cs") wich did not have the control ID. I just deleted it and the problem was deleted together.
If lblDateShow
is in the markup of your master page, but it appears not to exist in the code-behind file, then it is most likely a problem with the designer.cs file for your master page. Is lblDateShow
instantiated there? If not, you will need to regenerate your designer file or add the Label manually.
Try putting it in the right namespace. That was my issue
精彩评论