在不更改关联类(usercontrol.cs)文件的情况下扩展用户控件中的事件,在 app_code 中添加为单独的类,这可能吗?原因:我使用的是 CMS (Ektron),所以我无法在 usercontrol.cs 文件中添加代码
代码示例:
用户控制 ascx 文件
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="Usercontrols_WebUserControl" %>
<asp:Button ID="Button1" runat="server" Text="Click me"
onclick="Button1_Click" />
用户控制 .cs 文件
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("clicked the button");
}
所以我需要通过创建一个新类或任何其他选项来添加一些其他代码(例如:Response.Write("clicked required button");) 到'Button1_Click'事件?