Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Label does not exist in the current context

Status
Not open for further replies.

collegian

Programmer
Jul 1, 2010
64
US
Hello All,

I am facing a weird issue.I have a label on the front end but when I try to use it on the code-behind and run my code I obtain an error: Label does not exist in the current context! The label is shown in intellisense and was working earlier.My team mate had created a back up of the file and it stopped working after that.I deleted the back up files and tried but it doesn't seem to work.Any suggestions will be greatly appreciated.

Thanks.
 
provide the code. in this case the markup and the code behind.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Here is the front end code:

<div id="weather">
<img src="sunny.jpg" alt="sunny" height="40px" width="40px"/>
<h3>Weather</h3>
<p><i>(5 minute Averages)</i></p>
<table>
<tr>
<td><b><font size="2px">Current Time</font></b></td>
<td><asp:Label runat="server" ID="Label_Time"></asp:Label></td>
</tr>
<tr><td><b><font size="2px">Temperature</font></b></td><td><asp:Label runat="server" ID="Label_Temperature"></asp:Label></td>
</tr>
<tr><td><b><font size="2px"> Relative Humidity</font></b></td><td><asp:Label runat="server" ID="Label_RH"></asp:Label></td>
</tr>
<tr><td><b><font size="2px">Wind Speed</font></b></td><td><asp:Label runat="server" ID="Label_WindSpeed"></asp:Label></td>
</tr>
<tr><td><b><font size="2px"> Wind Direction</font></b></td><td><asp:Label runat="server" ID="Label_WindDirection"></asp:Label></td>
</tr>
<tr><td><b><font size="2px">Total Precip</font></b></td><td><asp:Label runat="server" ID="Label_Precip"></asp:Label></td>
</tr>
</table>

</div>


This is the code behind:

Label_Temperature.Text = split[0].ToString() + "&deg;C" + " " + split[1].ToString() + "&deg;F";
Label_RH.Text = split[2].ToString() + "%";
Label_WindSpeed.Text = split[3].ToString() + "m/s" + " " + split[4].ToString() + "mph";
Label_WindDirection.Text = split[5].ToString() + "&deg;";
Label_Precip.Text = split[6].ToString() + " " + "1in";
TimeSpan dt = System.DateTime.Now.TimeOfDay;
string t = dt.Hours.ToString() + ":" + dt.Minutes.ToString() + ":" + dt.Seconds.ToString();
Label_Time.Text = t;


I am getting an error that these labels do no exist in the current context.
 
the syntax looks good from here. do you get the error at compilation or runtime? a compilation error may be that the field is missing from the designer.cs file.


Jason Meckley
Programmer

faq855-7190
faq732-7259
 
I get a compile time error when I build the website.What does a missing field from designer.cs file mean? I am sorry, I did not understand it.
 
the aspx file is the markup the aspx.designer.cs file is where all the MS auto-generated code goes. when you drag a control onto the form the designer.cs file is re-written. open up the file and take a look the controls/fields match up to the markup, which matches up to what you use in the aspx.cs file (your code).

chances are either the field is missing or the properties of that field are incorrect.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Is there any special method to view these files? I am using VS-2010 professional and I do not see the aspx.designer.cs files by default,I just have the .aspx and .aspx.cs files visible.
 
2010 doesn't have those files. Just try recreating the page from scratch.
 
Yes,I deleted the page and created it again but even that doesn't work! Is it because of the fact that there exists some reference of the deleted duplicate files somewhere in the project?
 
Are the namespaces and class names correct between the aspx page and codebehind file?

Rhys

"The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it"
Terry Pratchett
 
Yes,the class name is the same on aspx and code behind but I am not using any namespaces.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top