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
Error speaks everything, just add
TextBox1_TextChanged
method toWebForm1
class.You probably have deleted the method from .cs class while event
TextChanged
on the form is still registered with methodTextBox1_TextChanged
.Either remove that registered event from the UI or add
TextBox1_TextChanged
event with proper parameters again in classProblem is in your aspx page. Search for that input and remove the event attribute containing TextBox1_TextChanged.
Very probably on your Form, in Visual Studio, there is a
TextBox1_TextChanged
method declared in theTextChanged
property of yourTextBox
, 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 theTextChanged
property and delete it.