C# 是否可以进行用户控制事件扩展?

C# 是否可以进行用户控制事件扩展?,c#,asp.net,class,user-controls,partial-classes,C#,Asp.net,Class,User Controls,Partial Classes,在关联类(usercontrol.cs)文件中扩展用户控件中的事件,并在app_代码中添加为单独的类,这可能吗? 原因: 我使用的是CMS(Ektron),所以我不能在usercontrol.cs文件中添加代码 protected void Button1_Click(object sender, EventArgs e) { Response.Write("clicked the button"); } 代码示例: 用户控制ascx文件 <%@ Con

在关联类(usercontrol.cs)文件中扩展用户控件中的事件,并在app_代码中添加为单独的类,这可能吗? 原因: 我使用的是CMS(Ektron),所以我不能在usercontrol.cs文件中添加代码

 protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("clicked the button");
    }
代码示例:

用户控制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" />

因此,我需要通过创建一个新类或任何其他选项来为“Button1_Click”事件添加一些其他代码(例如:Response.Write(“clicked needed button”);)来实现这一点。

在aspx页面上处理button Click事件就足够了吗?如果是这样,则需要将事件从控件公开到页面。请看下面的帖子:


只有将main.cs文件中的类定义为时,才可能执行此操作。否则不行。

sry这不是我想要的,我想要的是在不更改用户控件的情况下为Button1\u Click添加一些逻辑。cs文件
Button1\u Click
应该使用
virtual
关键字编写;您应该派生usercontrol类并重写该方法;然后在aspx页面中使用该派生实例。否则就没有别的办法了……我想//祝你好运//因为我的研究分部类方法无法在扩展类中重写,而不创建继承分部类的新类。