Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Events between user controls

Status
Not open for further replies.

iaswnidou

Programmer
Apr 19, 2005
140
0
0
GR
Hello

I have 2 user controls within a webform. I want to raise an event on one of them and be handled in the other one by subscribing to it.
So in the first one i have these declarations
Code:
public event EventHandler ImportUsers;

protected void OnImportUsers(EventArgs e)
{
 if (ImportUsers != null)
 { ImportUsers(this, e); }
}

Can you tell me what sort of code i need in the other one to subscribe to it?

Thanks
 
I think it would look something like this.
Code:
public class UC1 : UserControl
{
   public event EventHandler ImportUsers;

   protected void OnImportUsers(EventArgs e)
   {
      if (ImportUsers != null) ImportUsers(this, e);
   }
}
public class UC2 : UserControl
{
   public void MyMethod(object sender, EventArgs e)
   {
      ...process
   }
}
public class MyWebPage : Page
{
  protected override OnInit(EventArgs e)
  {
      this.UC1.ImportUsers += new EventHandler(this.UC2.MyMethod);
  }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thank you very much for your quick response. I guess you must be right. I will try it later and let u know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top