0

The name lblorder does not exist in the current context label

<asp:Label ID="lblorder" runat="server" Text="Ordernumber: "></asp:Label>

code behind

string test = lblorder.Text;

I hate this error. Once in a while it just pops up and I know that it has something to do with deleting the aspx.designer.cs and rebuilding the page or solution file but I work in Visual Web Developer 2008 Express Edition and I dont have this aspx.designer.cs file

..help me..

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Sjemmie
  • 1,249
  • 8
  • 26
  • 31

4 Answers4

1

You could always open the visual studio solution and add the xml for the file.

<Compile Include="blahblah\blahblah.ascx.cs">
  <DependentUpon>blahblah.ascx</DependentUpon>
</Compile>
Kevin
  • 11
  • 1
0

I too had the same problem but I fixed it by providing the directive in the aspx file (html file)

The above format and content can be obtained by making a new web application project and copything the above similar directive that is automatically generated by visual studio!!

0

Once you delete the aspx.designer.cs you should be able to right click on the .aspx file and click "Convert to Web Application". This will regenerate you aspx.designer.cs file.

Larry Hipp
  • 6,205
  • 3
  • 26
  • 31
  • hipplar, the question pointed out that this cannot be done in VWD Express – Michael Paulukonis Jul 19 '11 at 13:35
  • Although this answer suggests it can: http://stackoverflow.com/questions/6008588/label-doesnt-exist-in-the-current-context – Michael Paulukonis Jul 19 '11 at 13:37
  • I've tried to delete the files (aspx + aspx.cs) and created new ones with the same filename but I still have the problem, and also with new filenames after deleting the original, it doesnt work – Sjemmie Jul 19 '11 at 14:14
  • 1
    Have you tried "Cleaning" the solution? Right click the solution file, click "Clean Solution", then rebuild. – Patrick Jul 19 '11 at 15:04
  • I created a webapplication of the website solution , so now I have aspx.designer.cs files and can clean the solution and convert it to a webapplication, but the error still exists .. :/ – Sjemmie Jul 19 '11 at 16:23
  • I just added the missing line in the designer file, now it works ; protected global::System.Web.UI.WebControls.Label lblorder; – Sjemmie Jul 19 '11 at 16:33
  • but this is not a perminent solution; the changes are deleted after every built .... could anybody help me please...! – Sjemmie Jul 19 '11 at 18:08
0

I created a webapplication of the website solution , so now I have aspx.designer.cs files and can clean the solution and convert it to a webapplication, but the error still exists .. So I just added the missing line in the designer file, now it works ; protected global::System.Web.UI.WebControls.Label lblorder; but this is not a perminent solution; the changes are deleted after every built .... and then she found it that you have to use a findcontrol when labels etc are placed in a nested repeater

Sjemmie
  • 1,249
  • 8
  • 26
  • 31