OutOFTouch
OutOFTouch

Reputation: 1067

How to raise events to page from Dynamically loaded user control?

I have user control that inherits a base control class and these user controls are loaded using the LoadControl method, I can't seem to figure out how to raise events from user controls to the page that are dynamically loaded this way.

Thanks

Here is the delegate and event in the base user control class.


public delegate void SomeChangeEventHandler(object sender
, SomeChangeEventArgs e);

public event SomeChangeEventHandler SomeChangeEvent; 

public virtual void OnSomeChanged(SomeChangeEventArgs e)
{
    if (SomeChangeEvent != null)
    {
       SomeChangeEvent(this, e);
    }
}

Upvotes: 0

Views: 1295

Answers (1)

Gabriel McAdams
Gabriel McAdams

Reputation: 58261

You can add event handlers manually like this:

MyUserControl myControl1 = (MyUserControl)LoadControl("ThisControl.ascx.cs");
myControl1.DataBinding += new System.EventHandler(this.MyControl_DataBinding);

Upvotes: 3

Related Questions