"Teemu Keiski" <joteke@aspalliance.com> wrote in message
news:%23ahwS0ryGHA.3632@TK2MSFTNGP04.phx.gbl...
> Hi,
>
> you need to expose it as full-blown event, not as property. Page parser in
> ASP.NET is then able to wire syntax On<EventName>="handler_method_name"
> into your event as listener. Therefore the code would be pretty much like
> asa follows. Read also the comments I've made into the code.
>
> /// <summary>
> /// Static key of all the event handlers
> /// </summary>
> private static readonly object EventClick = new object();
>
> /// <summary>
> /// This is the event where event handlers are collected into a
> EventHandlerList
> /// Page parser parses them from declarative syntax or you add them in
> code
> /// </summary>
> public event EventHandler Submit
> {
> add
> {
> Events.AddHandler(EventClick, value);
> }
> remove
> {
> Events.RemoveHandler(EventClick, value);
>
> }
> }
>
> /// <summary>
> /// This method is used to raise Submit event. Do not *confuse* with
> aspx's OnSubmit="method_name" syntax
> /// </summary>
> /// <param name="e"></param>
> protected virtual void OnSubmit(EventArgs e)
> {
> EventHandler handler = Events[EventClick] as EventHandler;
> if (handler != null)
> handler(this, Error);
> }
>
> /// When handling Button's click inside the control, you'd call
> this.OnSubmit(EventArgs.Empty);
> /// when you want the event to be raised
>
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
>
http://blogs.aspadvice.com/joteke >
>
> <paul.hester@gmail.com> wrote in message
> news:1156742811.599520.168410@m73g2000cwd.googlegroups.com...
>> Hi all,
>>
>> I have a custom server control that can contain one or more buttons.
>> I'm trying to expose an event handler as a property so that the buttons
>> can fire a click event when clicked. However, I'm getting the following
>> error:
>>
>> Cannot create an object of type 'System.EventHandler' from its string
>> representation 'OnSubmit' for the 'OnSubmit' property.
>>
>> My control's tag looks like this:
>>
>> <stuff:MyControl OnSubmit="OnSubmit" Width="430"
>> runat="server">...</stuff:MyControl>
>>
>> The property looks like this:
>>
>> public EventHandler OnSubmit
>> {
>> get { return _onSubmit; }
>> set { _onSubmit = value; }
>> }
>>
>> I've tried the property with and without a type converter without
>> success.
>>
>> Any help would be much appreciated.
>>
>> Thanks,
>>
>> Paul
>>
>
>