Declare the event in the UserControl and create a method that raises it. The event is named "SelectionChanged".

UserControl.ascx

/// <summary>
/// Event to be raised by control when the selections change
/// </summary>
public event EventHandler SelectionChanged;

protected virtual void OnSelectionChanged(EventArgs e) {
    SelectionChanged?.Invoke(this, e);
}

Add an event handler for the event in the page which contains the UserControl. In this case, the ID of the UserControl is "Toolbar".

Page.aspx

protected void Page_Load(object sender, EventArgs e) {
    Toolbar.SelectionChanged += new EventHandler(Toolbar_SelectionChanged);
}

private void Toolbar_SelectionChanged(object sender, EventArgs e) {
    // Event raised from page - do stuff here
}

For VB.Net examples, see various projects (e.g. WPHO)

Published On: February 5, 2019Categories: ASP.NetTags: ,