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" %>
...
...
Nitin SontakkePosted Jan 1, 2023, 6:46 AM
Any reason why you are introducing class Test to the mix? I am just curious to know / understand the rationale behind the thought process, that's all.
Valerie MeunierPosted Jan 1, 2023, 10:42 PM
If, as such saying 'but it seems to be impossible' is incorrect, if If I'm using hammer instead of screwdriver, could you use the screwdriver and show me a way to solve this? Once more, I would never do this in a real application, but I just wonder whether this is possible.
Nitin SontakkePosted Jan 1, 2023, 3:49 PM
Surprised a bit that you accepted my question as an answer. Thanks, nonetheless.
Please allow me to state following in response your closing remarks:
If you ask me, you are using hammer instead of screwdriver. As such saying 'but it seems to be impossible' is incorrect.
ASP.NET is FRAMEWORK which built using OOP principles on top of .NET framework which itself tries to leaverage OOP concepts.
Just to give you one example, all ASP.NET controls are inherited from WebControl class and implement several interfaces.
Being a framework, developed with a specific use case (web app development) it has its own limitations which we can call restrictions.
Please note however, that wherever possible, it also supports inheriance as well.
https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.textbox?view=netframework-4.8
Hope it helps / clarifies.
Thank you, again!
Valerie MeunierPosted Jan 1, 2023, 1:41 PM
Thanks for replying. I know it's unual, but i did it just to experiment and to see how to use OOP in asp.net. But it seems to be impossible.
Sachin SinghPosted Jan 1, 2023, 7:44 AM
As far as i know, you can't this, OOps conecpt are not applicable with System.Web.UI.Pages , so object creation, inheritance etc should not be used.