Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 82.4k

webform1_aspx does not contain a definition for TextBox1_TextChanged

Dec 30 2022 1:06 PM

Hi

I'm experimenting with classes in asp.net. I try to put an event into a new class, but this is the error i get: CS1061: 'webform1_aspx' does not contain a definition for 'TextBox1_TextChanged' and no accessible extension method 'TextBox1_TextChanged' accepting a first argument of type 'webform1_aspx' could be found.

Thanks for help.

V.

using System;
namespace test
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        public string a = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            TextBox1.Focus();
        }
    }

    class Test 
    {
        WebForm1 wb = new WebForm1();
        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            wb.a = wb.TextBox1.Text;
            wb.Label1.Text += wb.a;
        }
    }
}

aspx file
---------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test.WebForm1" %>
...
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
...


Answers (3)