Home All Groups Group Topic Archive Search About

Exposing an event handler as a control property

Author
28 Aug 2006 5:27 AM
paul.hester
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

Author
28 Aug 2006 1:25 PM
Alvin Bruney [MVP]
I'm not sure what you are trying to accomplish with this approach. You
probably only need a setter function which would simply fire the onSubmit
event not assign it to an event variable since that doesn't accomplish much.

I don't see a reason for a getter either. What are you getting? A fired
event? In that case the correct event handler is already invoked.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


<paul.hes***@gmail.com> wrote in message
Show quoteHide quote
news:1156742868.804718.265710@i3g2000cwc.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
>

Bookmark and Share

Post Thread options