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" %>
...
...
Pasang TamangPosted Dec 30, 2022, 1:40 PM
Hi,
Below code should be inside WebForm1 class
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
wb.a = wb.TextBox1.Text;
wb.Label1.Text += wb.a;
}
Regards,
Pasang
Valerie MeunierPosted Dec 30, 2022, 2:50 PM
Thansk for replying, but if the code below is in the WebForm1 class, of course it will work. I'm trying to put an event (like TextBox1_TextChanged) into another class and to activate it from there.
Pasang TamangPosted Dec 30, 2022, 1:48 PM
Please check below code
Regards,
Pasang