Fixing “name does not exist in the current context” errors in Web Developer Express

≡放荡痞女 提交于 2019-12-13 05:37:11

问题


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..


回答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>



回答2:


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.




回答3:


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




回答4:


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!!



来源:https://stackoverflow.com/questions/6747551/fixing-name-does-not-exist-in-the-current-context-errors-in-web-developer-expr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!