Server Side Event Handler Generation From ASP.NET Markup in Visual Studio 2011 Developer Preview
By | October 19, 2011

This is really a great addition in Visual Studio 2011 Developer Preview for ASP.NET developers. If you are familiar with  WPF and XMAL development in Visual Studio, it should be well known for you, because  preview version of Visual Studio supports  generation of  event handler code from XMAL markup itself.  With Visual Studio 2011 developer preview, creating event handlers for ASP.NET controls have become significantly easy. You really don’t not need to write the event handler manually or  generating the even handler from design view.

In VS 2011 Developer preview, markup intellisense for all ASP.NET server-side events will show you list of exiting handlers and a value called “<Create New Event>” . Which means you can attach the event with some exiting event handler or  select “create New event” to generate an new  handler with the right signature in the code-behind file.

 Server Side Event Handler Generation From ASP.NET Markup in Visual Studio 2011 Developer Preview

If there is no control Id provided, Visual Studio will consider the control id as “Unnamed” and will generate the event handler as shown in below.

 Server Side Event Handler Generation From ASP.NET Markup in Visual Studio 2011 Developer Preview

 Server Side Event Handler Generation From ASP.NET Markup in Visual Studio 2011 Developer Preview

If you are wondering  about what will happen if there are multiple controls  without ids, does Visual studio going to attach with same event handler? No, It will  append an incremental number with event handler name.

 Server Side Event Handler Generation From ASP.NET Markup in Visual Studio 2011 Developer Preview

Visual Studio will generate Event handler name as <ControlName>_Click if control id is provided.

 Server Side Event Handler Generation From ASP.NET Markup in Visual Studio 2011 Developer Preview

 Server Side Event Handler Generation From ASP.NET Markup in Visual Studio 2011 Developer Preview

Interesting ? Well, you can check out few more interesting addition over here Few Nice features in Visual Studio 11 Developer Preview for ASP.NET Developers

Cheers

Aj