dynamic control event

Discussion in 'C#' started by pw_jamison, Aug 28, 2010.

  1. pw_jamison

    pw_jamison New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    i know this partially asp.net as well...


    if i create an custom control like this

    protected void Page_Load(object sender, EventArgs e)
    {
    Control myUserControl = (Control)LoadControl("MyControl.ascx");
    PanelX.Controls.Add(myUserControl);

    is there a way of responding to an event within that control...

    private void Button1_Click(object sender, System.EventArgs e)
    {
    Response.Write("WebUserControl1 :: I am in the control");
    }

    without specifically creating an instance of the control...

    MyControl realControl = new MyControl();
    realControl.myEvent += new EventHandler(FormEvent);

    Where FormEvent is an event on the form triggered by the event on the control.

    hope this makes sense.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice