Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 82.9k

CS1061: error with TextBox1_TextChanged

Dec 30 2022 3:20 PM

Hi,
this time, i'm trying to put event TextBox1_TextChanged into class Test and to call it from class WebForm1. Because Test inherits from WebForm1, it inherits all the fields and methods, and also event TextBox1_TextChanged, i thought. So i was expecting that it would run. But i still get this error below (from aspx file). Maybe it's impossible to do like this?
Thansk again. V.

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.

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();
        }

        protected void txtch()
        {
            a = TextBox1.Text;
            Label1.Text += a;
        }

    }

    class Test : WebForm1
    {
        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            txtch();
        }
    }
}

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 (5)