Reputation: 632
I have two Classes. MyClass.cs
and anotherClass.cs
MyClass.cs
contains textbox1
, and KeyDown
event "textbox1_Keydown(object sender, KeyEventArgs e)
".
My question is, how do I activate the Keydown event of textbox1
from AnotherClass.cs
?
Upvotes: 1
Views: 222
Reputation: 86
You can do that in your aspx code behind c# code. However if you want to use controllers in new c# class you can follow these steps.
<%@ Page Title="" Language="C#" MasterPageFile="~/CRM/CRM.Master" AutoEventWireup="true" CodeBehind="CRMTRN02.aspx.cs" Inherits="CRM.CRMTRN02" %>
<%@ Page Title="" Language="C#" MasterPageFile="~/CRM/CRM.Master" AutoEventWireup="true" CodeBehind="Class1.cs" Inherits="CRM.C" %>
Add like these if you use master page.First line is already added when page created. You can add second line like above.
Then in your Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
namespace XONTCRM
{
public partial class C
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
Now you can access your controllers in aspx page in your Class1.cs file. you can enable disabel and do whatever you think.....
Upvotes: 0
Reputation: 1986
There are ways to do it, but it will lead to code that is hard to maintain.
I assume that you don't really want to trigger the event, but that you want to get the same behaviour as if you triggered the event.
My suggestion is to move the code in textbox1_Keydown()
to a method in another class and call that method from both textbox1_Keydown()
and Class.cs
.
Upvotes: 3