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.
//Default.aspx:
<custom:FormShell ID="Shell1" OnOk="MyFunction" >
<custom:FormShellContent runat="server">
<p>Some Content</p>
</custom:FormShellContent>
</custom:FormShell>
Here is an example (that does not work) of what I am trying to accomplish in code (see last setter).
//FormShell.cs:
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); }
}
}
}