views:

406

answers:

1

So i've got a custom user control. I have an event (SelectionChanged) and I'm wanting to have who ever uses my control to do the following to hook up the event:

  1. drag the control to the page
  2. in designer mode, click on the control
  3. view the controls event handlers (from the properties window)
  4. find the SelectionChanged event
  5. double click and let visual studio create the code behind function and the wire-up on the aspx page.

How do i get this done? I've got the control setup so that the user can manually type in the event wire-up and code behind event by hand, but i want Visual Studio to do this.

Currently, when the a developer has dropped my control on the page, they can click on it and see the properties but no events are available (the lightning bolt isn't even there).


My events are public. Here they are:

public delegate void SelectionChangedDelegate(object sender, SelectionChangedEventArgs e);
public event SelectionChangedDelegate SelectionChangedEvent;
+2  A: 

I don't understand how the lightning bolt isn't there. Is your control inheriting from System.Web.UI.HtmlControls.HtmlControl or System.Web.UI.Control or another derive control?

If you are inheriting from one of these controls, you should see the inherited events in the properties window.

The fact the lightning bolt isn't there leads me to believe that you aren't inheriting from one of the the control classes.

EDIT: Well, you're not going to like this. UserControl doesn't behave the same as a WebControl. And as such, the VS Editor doesn't wireup the events.

If the Event Wireup is critcal for you (If this is going to be a sold library) I would recommend that you rewrite the control as a WebControl. This will require you to add all the controls programatically in the CreateChildControls override method.

You might also be able to wrap your UserControl inside of a WebControl and bubble up all the events that way.

Best of luck!

Chris
Here's the declaration of my class: public partial class UC_SiteBar : System.Web.UI.UserControl
Miles