Extend an event in a user control with out changing in the associated class (usercontrol.cs) file, add as separate class in app_code ,is that possible? Reason: I am using a CMS (Ektron), so i cant add code in usercontrol.cs file

code sample:

user control ascx file

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="Usercontrols_WebUserControl" %>
<asp:Button ID="Button1" runat="server" Text="Click me" 
    onclick="Button1_Click" />

user control .cs file

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

so i need to add some other code (eg: Response.Write("clicked needed button");) to 'Button1_Click' event by creating a new class or any other option to achieve this?

有帮助吗?

解决方案 2

Would handling the button click event on the aspx page suffice? If so then you'd need to expose the event from the control to the page. Have a look at the following post:

how to add an event to a UserControl in C#?

其他提示

This is possible only if class in main .cs file is defined as partial class. Otherwise not.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top