Compilation Error

2019-07-23 08:15发布

Im getting a compilation error when running this code:

    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";
                   }   
    }
  }    
}

Here is the Compiler Error Message: CS1061: 'ASP.webform1_aspx' does not contain a definition for 'TextBox1_TextChanged' and no extension method 'TextBox1_TextChanged' accepting a first argument of type 'ASP.webform1_aspx' could be found (are you missing a using directive or an assembly reference?)

What does this mean and how can I correct it? Thanks

3条回答
孤傲高冷的网名
2楼-- · 2019-07-23 08:54

Error speaks everything, just add TextBox1_TextChanged method to WebForm1 class.
You probably have deleted the method from .cs class while event TextChanged on the form is still registered with method TextBox1_TextChanged.
Either remove that registered event from the UI or add TextBox1_TextChanged event with proper parameters again in class

查看更多
【Aperson】
3楼-- · 2019-07-23 08:57

Problem is in your aspx page. Search for that input and remove the event attribute containing TextBox1_TextChanged.

查看更多
做个烂人
4楼-- · 2019-07-23 09:15

Very probably on your Form, in Visual Studio, there is a TextBox1_TextChanged method declared in the TextChanged property of your TextBox, while there is no implementation.

You may have had that implementation (an empty method) and then deleted it, without deleting the reference to it in the UI in Visual Studio. So open your Form in Visual Studio, click on the TextBox1, look for the value in the TextChanged property and delete it.

查看更多
登录 后发表回答