14

In work and in home I have VS2010 installed. But in work I have this one cool feature. On the code behind file I have two drop downs. When I select some object in the left one lets say a testButton or Default2 (a page class), on the right one I get all available events for that object and when I select an event Visual Studio autogenerates it in my code-behind file. In my home VS I actually have does 2 drop downs but they work different. I have available objects on the right one but when I select for example the testButton it shows me the aspx page and points this button :/ Should I set sommething in the VS configuration or maybe in work I have some addon which I'm not aware of? Any ideas?

enter image description here

shin
  • 666
  • 2
  • 9
  • 25

9 Answers9

9

This is not a VB-exclusive feature.

What you're looking for is called a navigation bar. In Visual Studio options, open Text Editor → C# → General, and you'll see an option called Navigation Bar. Enable it and click OK.

Navigation bar in Options

However, I believe this bar works a bit differently in VB and in C#. In C#, it only lists the existing classes and their methods; in VB, it will list all your controls and their events even if those don't exist yet.

configurator
  • 40,828
  • 14
  • 81
  • 115
  • I think you misundarstand me. I had that navigation bar in my c# files but I hadn't that funcionality and I asked why. Later on I wroted an answer in comment to my second post that this feature was only available in VB. (saying "this feature" I meant autogenerating events from that drop downs) – shin Feb 20 '11 at 10:45
  • As mentioned, you misunderstand the issue. It's not that the Navigation Bar is a VB only feature, its what it does. In VB only, it will list all objects and upon selecting one, you can then see and select the events for that object and an event callback method stub will be generated. – Scott Marcus Sep 24 '14 at 14:19
7

You need to go the design view, in the Properties box, click on Events (lighting bolt) and double click on the events you want to code behind:

enter image description here
(source: byte.net)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Steven Chang
  • 94
  • 1
  • 3
  • This solution worked for me. I needed to add the Shown event, and this had the same effect as double-clicking a button to add it's Click event. Thank you! – CigarDoug Oct 30 '15 at 15:47
7

Ok I think I've found the answer. It seems that this feature is only available when the current file is in VB.Net. In my opinion this suks :/

shin
  • 666
  • 2
  • 9
  • 25
  • I can't answer, but I can confidently say it is not a VB.NET exclusive feature. – Grant Thomas Feb 19 '11 at 20:28
  • When I add new VB.NET page in the solution everything works ok. Here is a fragmet from book saying about it : http://books.google.pl/books?id=9YP4gDsXSWoC&pg=PA41&lpg=PA41&dq=visual+studio+navigation+bar+with+available+event+list&source=bl&ots=00TJByitD1&sig=mu3jV_vZ6Naa9fJH8KsqzGFFKO8&hl=pl&ei=4CRgTZadNZDHsgbvwPW2CA&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBYQ6AEwAA#v=onepage&q&f=false – shin Feb 19 '11 at 20:32
  • I feel like my confidence should take quite a knock here, but don't think it will until I see this for myself! I'll let you know. – Grant Thomas Feb 19 '11 at 20:46
  • Your assertion that this feature is only available when the current file is VB.NET is incorrect. I use this feature all of the time with C# files. See my answer. – tomfanning Feb 20 '11 at 00:39
  • When you say this feature you mean navigation bar or that in C# you can generate events from navigation bar? Can you i c# select from left drop down a declared button and then on the right one you have all its available events and when you select one that you havent written in your code behind it will autogenerate a function for you? – shin Feb 20 '11 at 11:34
  • That wasn't the original question. – tomfanning Feb 25 '11 at 13:19
  • 1
    Yes it was..."In my home VS I actually have does 2 drop downs but they work different." The question was about why they work different not how to show them... – shin Feb 28 '11 at 08:12
  • @GrantThomas - You are mistaken. It is an exclusive VB feature, not available in C#. As I've mentioned, it is widely documented and has been reported to MS on several occassions. – Scott Marcus Sep 24 '14 at 14:20
  • In VB, all events are shown. In C#, only added events are shown. To add an event not shown in C#, see Steven Chang's answer below. – CigarDoug Oct 30 '15 at 15:49
5

@shin is correct, this is a VB.NET only feature; Microsoft only had feedback reports dating back to 2004 mentioning this feature, so I have opened a new bug request with Microsoft regarding this; and also added feedback to Visual Studios account on UserVoice...

https://connect.microsoft.com/VisualStudio/feedback/details/688175/vs2010-c-add-page-event-handlers-to-asp-net-using-codebehind-navigation-bar-the-same-way-as-in-vb-net

http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2244558-allow-c-to-add-event-handlers-to-classes-using-co

I encourage everyone who this issue effects to go and vote up & confirm this issue with them.

I dislike that C# doesn't provide such a useful time-saving function.

simbolo
  • 7,279
  • 6
  • 56
  • 96
  • 2
    Microsoft have responded to my bug request, they say that C# events can be added from the codebehind automatically in the next version of Visual Studio after 2010. – simbolo Sep 30 '11 at 04:31
  • Next version means Visual Studio 2011,I feel sad :/ – DayTimeCoder Mar 04 '12 at 04:57
  • This is probably the only instance where VB has an edge. – FarFigNewton May 16 '12 at 18:58
  • @guanome, not only imho, if you ever seriously write a project in vb.net the intellisense and error detection they are very good compare to c#. i do both, but i find myself code faster in vb than c#. – Tom Aug 09 '12 at 08:30
  • @Tom I write VB almost everyday and I would say they are generally equal, but I find that creating properties in C# is a lot quicker and easier. Oh and creating a multiline string in C# is sublime. – FarFigNewton Aug 09 '12 at 13:14
  • Well a big advantage for VB is that compiles in realtime so error checking/intellisense is instant, C# only finds errors when you try to build. Plugins are required to emulate this behaviour in C#. – simbolo Aug 09 '12 at 20:32
3
  1. Up to Visual Studio 2010, only Vb.net has this feature: on code-behind page, the code panel upper-left drop down shows a control's name, and the right drop down shows this control's available events. When clicking this event we can get the code-block for this event. This feature is not available in C#.

  2. Without above feature, we can still get a control's available events for both C# and Vb.net: We must select the control on the aspx page and choose the design view at the lower left corner, then on the Properties panel click the Event button (the lighting sign), then available actions will be shown, double-click the name of the event you want, the event code will be generated in code-behind.

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
Jason
  • 31
  • 1
2

It is most certainly is a VB only feature and has been reported on numerous occassions to Microsoft.

Scott Marcus
  • 64,069
  • 6
  • 49
  • 71
1

It is possible to see all the available Events in C# & Asp.net too, but not inside code window as possible in VB. But you can see all Events of any selected Control in its Property Window. Open Properties, then Click Events.

Nightfirecat
  • 11,432
  • 6
  • 35
  • 51
0

This and the feature to generate event handlers without having to switch to Design view for C# is finally coming in Visual Studio 2012. It was about time.

Saeb Amini
  • 23,054
  • 9
  • 78
  • 76
0

Even the 2012 feature is not enough. You still have to guess for Page level events (Init, PreRender, etc) and also files that haven't already been filled out for you like Global.asax, which depending on the template you started with may or may not have all the event handlers already specified.

Agreed that Event Handlers is one of the things VB has for years and years and years handled way better than C#. I can't count the number of times I've had to remind a fellow C# developer that some events do, in fact, exist.