Exposing an event handler as a control property

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

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
 
THe compliler is saying that that the string value "OnSubmit" which you
supplied for the property OnSubmit does not cast to type EventHandler.

As far as I know, you will need to declare an event in the control,
then, the pages that use the control will need to wire event handers up
to the event using the += syntax.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top