UserControl Events Handled by Page
Maybe you'll need it someday, maybe you've done it, maybe not :) But I needed to raise an event from a usercontrol, which had to be handled in the containing page. Why? Because I created a RowFilter for a DataView in the usercontrol, and this DataView needs to be bound to a DataGrid on the page. There may be other/better ways, but this worked for me:
The code in the usercontrol:
//Declare custom public event handler
public event EventHandler Bind;
private void btnFilter_Click(object sender, System.EventArgs e)
{
//...create dataview and rowfilter
//raise custom event
Bind(this, e);
}
The code in the containing page:
private void Page_Load(object sender, System.EventArgs e)
{
//...Load usercontrol (filter1)
//Specify EventHandler in Page to handle Event raised in usercontrol
filter1.Bind +=new EventHandler(filter1_Bind);
}
private void filter1_Bind(object sender, EventArgs e)
{
//Respond to event raised (Bind dataview to datagrid)
}