Issues with propagating asp.net user management events

I have a simple user control that contains some buttons that fire events that I want the page to handle using the control. I have my code setup as such:

public event EventHandler Cancel;
public event EventHandler Confirm;
public void Confirm_Click(object sender, EventArgs e)
{
    if (Confirm != null)
        Confirm(this, e);
}
public void Cancel_Click(object sender, EventArgs e)
{
    if (Cancel != null) 
        Cancel(this, e);
}

but when I try to call them from a page using the control page load event, I don't get any custom events

Aspx code

<%@ Register TagPrefix="btg" TagName="CustomControl" Src="~/Search/CustomControl.ascx" %>
<btg:CustomControl ID="btgControl" runat="server" ></btg:CustomControl>

maybe it is because my buttons in the user control are inside the update panel?

+3
source share
1 answer

You should not see methods. You should see events.

:

myUserControl.Cancel += new EventHandler(myUserControl_Cancel);

, , . :

void myUserControl_Cancel(object sender, EventArgs e) {}

. , , .

edit: myUserControl - . , , init.

:

? .. web.config ?

, ? /, , . , :

UserControl control = Page.LoadControl("~/ControlPath/ControlName.ascx");
((MyUserControlClass)control).Cancel += += new EventHandler(myUserControl_Cancel); // etc...
+1

Source: https://habr.com/ru/post/1727510/


All Articles