views:

1335

answers:

4

Calling all Visual Studio gurus — when I'm working on a .ascx or .aspx file in a c# web project, the events do not show up in the properties panel unless I switch into the design view from the code view. Is this an intentional functionality of Visual Studio? Both VS2005 and VS2008 seem to work this way.

And is there any way to get the events to show up in the properties panel all the time?

+1  A: 

Yes, that's how Visual Studio is intended to work. This doesn't help you view them in properties panel, but you can get a list of events (among other things) by typing the following in the code-behind:

"this." and intellisense should show you a list.

What I typically do is override the OnInit method and put all event handler mappings in there. So that it looks something like this:

override protected void OnInit(EventArgs e)
{
  this.Load += new System.EventHandler(this.Page_Load);
  this.myButton.Click += new System.EventHandler(this.myButton_Click);

  base.OnInit(e);
}

If you do it using intellisense, as soon you type in "+= " you'll have the option to auto-complete that line and the event handler method's signature as well.

Kon
A: 

Yep, I wish we had a similar level of event autocompletion that we get with WPF where you can see the event name in IntelliSense and get it to automatically create a new stub event for you in code behind :(

Steven Robbins
+3  A: 

I don't know if that's the way VS is 'intended to work, but yes that's a limitation. In case you've noticed sometimes clicking on the control and pressing F4 (or clicking on the properties tab) fails to load the properties for the correct control, and then you gotta select it from the list.

Sigh

That apart, if you make a usercontrol of your own, and give it an event, that event will not show up in the properties tab when you put it on a page. You'll have to capture it manually in the Page_Init event (like demonstrated by fallen888).

These days I don't bother with going to the properties tab to see an event. You can just as well type the event's name in the mark-up and then write it in the code-behind file.

Cyril Gupta
A: 

This sucks dick, cant Microsoft fix this or is this to hard? I work alot(!) programmaticly and this sucks 'cause I need to go every f'ing time to split view, wich takes load(render) time. And then its still not a guarantee the events show. WTH? not development friendly is it..

B..