To fire an event:
//1st declare the event and event handler:
public event EditHomesHandler EditHomes;
public delegate void EditHomesHandler(object sender, EditMoviesEventArgs e);
public virtual void OnEditHomes(EditMoviesEven
if (EditHomes != null)
EditHomes(this, e);
}
//2nd call the event from
protected void SomethingClicked(object o, EventArgs e){
this.OnEditHomes(new EventArgs());
}
To catch the above event: lets say that the above event was declared in a user control of type AdminHomeControl. On a page we have declared a control of that type (protected AdminHomeControl ctlHome). Just add an event handler to the page for that control like you do for buttons.
protected void Page_Load(object o, EventArgs e){
//add an event listener
ctlHome.EditHomes += new EditHomesHandler(EditHomes
}
protected void EditHomesHandler (object o, EventArgs e){
//some code here to handle the event
}
Another really helpful thing is to sometimes pass data along with the event instead of the plain EventArgs. To do this you need to create a seperate class that inherits from EventArgs. You then can create properties and members for the class and use it instead of EventArgs in the above example.
Main Topics
Browse All Topics





by: Arthur_WoodPosted on 2006-05-06 at 18:18:28ID: 16623410
The 'previous page' no longer exists in memory. So you can't raise an event from the 'previous' page.
AW