Exposing an event handler as a control property

You need to expose it as full-blown event, not as property. Page parser in
ASP.NET is then able to wire syntax On=”handler_method_name” into
your event as listener.

    #region Event Handlers
    public delegate void OnAddressSavedHandler(object sender, AddressEventArgs e);

    public class AddressEventArgs : EventArgs
    {
        public Int64 AddressID;
        public AddressEventArgs(){ }
        public AddressEventArgs(Int64 val)
        {
            AddressID = val;
        }
    }
   

    public OnAddressSavedHandler OnAddressSaved;
    public event EventHandler AddressSaved
    {
        add { Events.AddHandler(OnAddressSaved, value); }
        remove { Events.RemoveHandler(OnAddressSaved, value); }
    }

    public virtual void RaiseAddressSavedEvent(Int64 addressID) //Call this method when the user changes
    {
        EventHandler handler = Events[OnAddressSaved] as EventHandler;
        if (handler != null)
            handler(this, new AddressEventArgs(addressID));
    }
    #endregion

Source


Leave a Reply