名称为“TextBox1中”不存在于当前上下文存在 [英] The name 'TextBox1' does not exist in the current context
问题描述
我得到这个错误:名称为TextBox1的'不在当前情况下存在
我的code:
命名空间WebApplication19
{
公共部分类默认:System.Web.UI.Page {
保护无效TextBox1_TextChanged(对象发件人,EventArgs的发送)
{
如果(TextBox1.Text ==MSC)
{
RadioButton2.Visible = FALSE;
DropDownList2.Visible = FALSE;
}
其他
{
RadioButton1.Visible = FALSE;
DropDownList1.Visible = FALSE;
}
}
}
}
在除了@迈克尔和@DGibbs给出的建议我也建议你双重和三重检查所有文件的类名(ASPX, ASPX.cs和ASPX.Designer.cs),以确保它们匹配,还有空间声明。
此外,除非这是概念只是一个快速和肮脏的证据,你应该给你的命名空间更具描述性的名称。东西比WebApplication19。
其他最后,很明显,该错误消息特别指出:名称为TextBox1中不存在于当前上下文
,而不是 TextBox1中存在。搜索您的code小写的 TextBox1中并重新命名它以匹配正确的大写的名称和应该得到你的code编译。
示例标记:
< ASP:文本框ID =TextBox1的=服务器ontextchanged =TextBox1_TextChanged>< / ASP:文本框>
I get this error: the name 'textbox1' does not exist in the current context
My code:
namespace WebApplication19
{
public partial class Default:System.Web.UI.Page
{
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
if (TextBox1.Text == "msc")
{
RadioButton2.Visible = false;
DropDownList2.Visible = false;
}
else
{
RadioButton1.Visible = false;
DropDownList1.Visible = false;
}
}
}
}
In addition to the advice given by @Michael and @DGibbs I'd also suggest you double and triple check the class names in all of your files (ASPX, ASPX.cs and ASPX.Designer.cs) to make sure they match, as well as the Namespace declarations.
Also, unless this is just a quick and dirty proof of concept, you should give your Namespace a more descriptive name. Something other than "WebApplication19".
Lastly, it's clear that the error message specifically states: the name 'textbox1' does not exist in the current context
and not TextBox1. Search your code for lowercase textbox1 and rename it to match the correct uppercase name and that should get your code to compile.
Example Markup:
<asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
这篇关于名称为“TextBox1中”不存在于当前上下文存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!