该名称在当前上下文中不存在 [英] The name does not exist in the current context
问题描述
我在asp.net 3.5应用程序中拥有一个主页,并且有一些控件和jquery东西.我尝试访问代码隐藏中的控件,它说:
I have a masterpage in my asp.net 3.5 application and I have some controls and jquery stuff. I try to access the controls in codebehind and it says :
The name 'DrpStates' does not exist in the current context
为什么无法在代码隐藏中访问它?
Why it is not accessible in codebehind ?
推荐答案
当您在文件后面创建代码时,ASP.NET还将自动生成一个设计器文件(紧邻该文件).在该设计器文件中,所有控件均已初始化并加载.有时(由于未知原因)在创建新控件时,它无法重新初始化设计器文件,并且您无法在文件后置代码中访问该控件.
When you create a code behind file, ASP.NET also automatically generates a designer file (which is right next to it). In that designer file all the controls are initialized and loaded. Sometimes (for reasons unknown) when you create a new control, it fails to re-initialize the designer file and you can't get access to the control in the code behind file.
尝试执行此操作>
- 删除设计器文件(右键单击>删除)
- 右键单击aspx文件>转换为Web应用程序
现在应该工作
这篇关于该名称在当前上下文中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!