How to pass a function to a Class on the presentation page. RRS feed

  • Question

  • User1456393972 posted

    I have a class that inherits from CompositeControl.  Inside my class, I have a button.  I want to declare the click event of the button from the presentation page. e.i.


    <custom:FormShell ID="Shell1" OnOk="MyFunction" >
         <custom:FormShellContent runat="server">                       
              <p>Some Content</p>                             

    Here is an example (that does not work) of what I am trying to accomplish in code (see last setter).


    using System; using System.Collections; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; namespace myControls { public class FormShellContent : Control { } [ParseChildren(true, "Items")] public partial class FormShell : CompositeControl { //Button protected Button myButton = new Button(); protected override void CreateChildControls() { //Add the button this.Controls.Add(myButton); //Add the content of the Formshell m_cell[1, 1].Controls.Add((Control)m_items[0]); } [Browsable(false)] public ArrayList Items { get { return m_items; } } //This does not work, How can I do something similar to //this so that i can declare the function from the presentation page? public event OkClick { set{ myButton.Click += new EventHandler(value); } } } }

    Tuesday, July 5, 2011 2:32 PM


  • User1456393972 posted

    Nevermind, figured it out.

      public event EventHandler OkClick
              myButton.Click += value;
              myButton.Click -= value;
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 5, 2011 2:43 PM