Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio keyboard shortcuts for creating Event handler stubs

When you edit a simple page in the design view, you can add an event on most components by simply double-clicking the relevant event. This does the binding and generates the function declaration in the codebehind for you.

In larger projects where the pages are complex, the design view can be extremely slow. Is there a way to quickly generate the codebehind stubs directly from the .aspx source?

like image 671
Console Avatar asked Dec 29 '22 20:12

Console


2 Answers

Just begin typing the 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 to typing the function name for the OnClick method...

for example, this part of the code:

OnClick="Function_Name_Here"

... Visual Studio will display a little pop-up window with the option to "<create new event>".

Select this option and the codebehind event handler stub will be generated for you.

like image 173
alonirock Avatar answered Jan 01 '23 10:01

alonirock


In the markup view the Properties window is still available: you may have it hidden.

When it's shown and the cursor is in the markup for a particular control, you get that control's properties and events like you would in Design view. Similarly, in the event tab you can double-click the event (i.e Click) to automatically generate an empty declaration in code and hook up the event without ever having to go into the Design view.

like image 37
Mark Avatar answered Jan 01 '23 08:01

Mark