Visual Studio Keyboard Shortcuts for Creating Event Handler Stubs

When you edit a simple page in the project view, you can add an event to most components by simply double-clicking the corresponding event. This links and generates a function declaration in codebehind for you.

In large projects where pages are complex, design can be very slow. Is there a way to quickly generate codes with direct access from an .aspx source?

+4
source share
3 answers

I was able to do this with ReSharper, but I have used it for so long that I don’t remember if Visual Studio had this feature initially.

+1
source

Just start entering code to create your component.

For example, this is the code to add a button to your .aspx file:

<asp:Button ID="ButtonAction" class="btn panel-black" runat="server" Text="" OnClick="Function_Name_Here" />

When you get the function name input for the OnClick method ...

for example, this piece of code:

OnClick="Function_Name_Here"

... Visual Studio will display a small popup with the option " <create new event> ".

Select this option and a codebehind event handler will be created for you.

+5
source

In the markup view, the Properties window is still available: it may be hidden.

When it is displayed, and the cursor is in the markup for a specific control, you get properties and control events such as in the Design view. Similarly, on the events tab, you can double-click an event (for example, click) to automatically generate a blank ad in the code and connect the event without inserting it into the Design view.

+2
source

All Articles