c# - 编译错误

标签 c# class webforms

运行这段代码时出现编译错误:

    namespace WebApplication1
{

public partial class WebForm1 : System.Web.UI.Page
{

   private Dictionary<string, string> _dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); // let's ignore case when comparing.

    protected void Page_Load(object sender, EventArgs e)
     {
        using (var reader = new StreamReader(File.OpenRead(@"C:/dictionary.csv")))
        {
            while (!reader.EndOfStream)
            {
                string[] tokens = reader.ReadLine().Split(';');
                _dictionary[tokens[0]] = tokens[1];
            }
        }
     }



    protected void Button1_Click(object sender, EventArgs e)
     {
            string output;
            if (_dictionary.TryGetValue(TextBox1.Text, out output))
                   {
                    TextBox2.Text = output;
                   }
             else
                   {
                    TextBox2.Text = "Input not recognised";
                   }   
    }
  }    
}

这是编译器错误消息:CS1061:“ASP.webform1_aspx”不包含“TextBox1_TextChanged”的定义,并且找不到接受“ASP.webform1_aspx”类型的第一个参数的扩展方法“TextBox1_TextChanged”(您是缺少 using 指令或程序集引用?)

这是什么意思,我该如何更正它? 谢谢

最佳答案

很可能在您的表单上,在 Visual Studio 中,有一个 TextBox1_TextChanged 方法在您的 TextBoxTextChanged 属性中声明,而那里没有实现。

您可能已经有了该实现(一个空方法),然后将其删除,而没有在 Visual Studio 的 UI 中删除对它的引用。因此,在 Visual Studio 中打开您的表单,单击 TextBox1,在 TextChanged 属性中查找值并将其删除。

关于c# - 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20330841/

相关文章:

asp.net - 导出功能在 IIS/SSL 网站上的 Zingchart 中不起作用

c# - 为什么要对 QueueBackgroundWorkItem 使用异步?

c# - 如何打开两个单独的(默认)浏览器窗口而不是新选项卡

调整 CSS 类填充的 jQuery 代码

ios - 如何在Parse中获取用户的FB ID?我可以访问AuthData吗?

c# - 将 asp.net 表单 View 从另一个页面更改为插入模式

c# - 在 RowDeleteing 事件中显示 ASPX Popup 控件 (ASPX Gridview)

c# - Azure 服务总线主题订阅者接收订单

c# - 使用自定义 WebApi Controller 的问题

Java enum.valueOf(String) 和 enum.class