HTML Editor Smart Tasks and Event Handler Generation (ASP.NET vNext Series)

This is the first in a series of blog posts I'm doing on ASP.NET vNext. 

The next release of Visual Studio includes a bunch of great code editing features (which I'll blog about more in the future).  Today's post covers some small, but nice, productivity improvements coming to the HTML Editor which will make it easy to quickly accomplish common tasks. 

In particular, Visual Studio will now support the ability to activate the "smart tasks" features of ASP.NET Server Controls, as well as easily wire up ASP.NET Server Control event handlers - without ever having to switch to design view.  You can now do these common scenarios equally well in source view.

Quick Video of the Features

Mads Kristensen has a nice 90 second video that shows off the HTML Editor Smart Tasks and Event Handler Generation features in action.  You can watch the 90 second video of these nice improvements here.

Below are some more details about the features and screen-shots of them in action.

Some Background on Smart Tasks

One of the productivity features we added to Visual Studio a few years back was support for "smart tasks".  Smart tasks enable you to click on a web form control, and then see (attached to the control) shortcuts that enable you to easily accomplish common tasks with it:

image

The smart tasks feature helps simplify a bunch of common scenarios.  The one downside to it, though, is that it has historically only worked in design mode.  If you are someone who prefers working within the HTML code editor and/or did not like to have to wait while the design view activates, then you weren't able to take advantage of these features.

Smart Tasks within the HTML Editor

The next release of ASP.NET and Visual Studio is adding support to enable smart tasks within source view (as well as design-view). 

With ASP.NET Web Forms, smart tasks appear as a small glyph when the caret is placed inside an ASP.NET Server control element:

image

You can expand the smart tasks either by clicking the glyph or by hitting CTRL+. (dot) just as in C# and VB.NET:

image

The above tasks can now be run directly from within source view - without ever having to switch to design-view - and can make it easy to quickly accomplish a lot of scenarios.  For example, we could change the column definitions of the GridView by clicking the "Edit Columns..." link which would immediately bring up this fields box (just like it would have in design-view):

image

When I configure the GridView column in the dialog box and click the OK-button, the following markup is inserted into the code editor - without me ever having to switch to design view or switch from the code editor:

clip_image001

We think smart tasks will offer a nice productivity boost and make a lot of tasks a lot easier.

Event Handler Generation in Source Code

One of the most common tasks you do with ASP.NET Server Controls is to wire-up server-side event handlers with them.

Today the only automatic way to do this within Visual Studio is to switch into design-view, select the control, and then either double click it (to handle the default event) or use the event tab of the property grid to select and name a specific event handler.  If you are someone who prefers to stay in code-view, having to switch to design view to accomplish this is a real pain.

The next release of ASP.NET and Visual Studio will make this easier, by supporting the ability to easily create and wire-up server-side event handlers from the HTML code editor as well.

Intellisense for all server-side events now include a value called "<Create New Event>" which, as the name implies, will create an event handler with the right signature in the code-behind file.   Simply type the event name, press space and it will show up:

clip_image002

You can choose to wire-up the event to any existing methods you might already have in you code-behind file, or simply type the name of a new event handler you want to create (or just hit tab to have it automatically name one for you):

clip_image004

Visual Studio will then automatically generate the appropriate server-side event handler within your code-behind file for you:

image

You can do all of this without ever having to switch into design-view, nor have to remember the exact names and signatures of the events you want to wire up.

Hope this helps,

Scott

P.S. In addition to blogging, I use Twitter to-do quick posts and share links. My Twitter handle is: @scottgu

65 Comments

  • Indeed Scott, these definitely seems to be give boost to the productivity.

    Looking forward for you next blogpost.

  • event handler generation looks cool.

    any idea on the release date?

  • I love the event handler generation from the markup.
    Thanks for sharing.

  • As someone who prefers to be in the code view as much as possible, this will save lots of time. The main reason to switch to design was for these features. Thanks to Scott and the team.

  • Thanks for sharing, this should be a great feature.

  • That event handler generation looks like something I would cheerfully use right now, and would cheerfully have used regularly over the last six years. Nice one!

  • So glad to see you blogging again Scott! Your posts are some of the most useful and valuable I've ever come across.

  • Looks good, anything to speed up time taken in html editor!

    I particularly like the event handler stuff, generally I still wire up events in OnInit to take advantage of the automatic event handler generation.

    Looking forward to the next posts

  • I do no have other words :)
    Awesome!!!

    Design View is slower than Source View. But such improvements make the development process easier.

  • Wow. Just what I was dreaming about, like, ever.

    Looking forward to the rest of the post series!

  • By the way do the VS team plans to do anything about the more general issue, that when you select an element on the page and open the Properties windows for the first time, it will show the properties of the page instead of the element. Then you have to select the item again. It can be annoying when it happens for the 100th times a day.
    However it works correctly if you right click the element and click Properties in the context menu.

  • I'm missing this features every day. Why we have to wait for vNext for such features!?
    Such smaller features should be rolled out via small updates/extensions to VS 2010.

  • Great improvements - should keep me well away from Design View from now on.

  • Event Handler Generation in Source Code is a great improvement! I work often in source code and switching to Designer view to create new events handler is boring. Thanks!

  • Those are very cool features.
    Working smartly from the Code Editor; hmmm, I can smell the productivity boost!
    Well done guys.

  • Great post Scott, nice to see you back.

    One thing that has always frustrated me is the size of the glyph when intellisense is present - why is it so small? Its a very small target area on a big screen, especially at the end of a long day, or when you try to use somebody else's machine. Would it be possible to provide an option to make this bigger?

  • This code works well and the idea behind it is a good one. I think it can be improved because seems to be a little bit unstable.

  • These shortcuts are going to be so useful, especially the handlers.

  • Coooooool, Just what I was looking for: "Event Handler Generation in Source Code"

  • Event handler generation is so cool. I always switch to design view to double click on this button because I absolutely don't feel like writing the event handler by hand even if I will do it faster. Now I get the best of both worlds.

  • That's great news! My coworkers & I have expressed the desire to do these from source view since .NET FW 1.0 (especially since switching to design view WAY back then reformatted your source view :)

    Both additions will be tremendously helpful time-savers.

    Will dragging a usercontrol onto source view also work like it does in design view (registering the control & giving it proper uc tag markup) instead of just a path to it, like it does now in source view?

    Looking forward to your subsequent posts. So glad you're blogging again!

  • Event handler generation will be a very welcome feature.. i'm just surprised it took so long to introduce. I've been asking for this since VS2005. better late than never :-)

  • Nice feature, which reminds me of the code window that contains the design time control in Visual Interdev 6.

  • Very good. I'm one of many people that doesn't like to go Design View. Very cool the event handler like WPF and Silverlight.

  • +1 to Event Handler Generation in Source Code. Long overdue.

  • dear scott,
    need a more simple data access model for silverlight, asp.net.
    Now is very difficult develop web app for business.

    Thank you and I'hope this post is publicated

  • Thanks! Design View just doesn't cut it for me (vs '08). Maybe I'm doing something wrong, but it seems slow and buggy compared to Code View. The event handling was the one thing I could have wished for.

  • Visual Studio 2010 crashes often and IIE Express locks up DLLs all the time... The IDE itself is slow as hell. What's going on... I don't want new features. I just want it to do the basic functions extremely efficient and well. Is this too much to ask Microsoft??? I am trying to move to Sublime Text 2 + Vim mode and power shell script and hopefully with practice I can eventually replace VS... Not sure if this is just a dream..,

  • I think the "Event Handler Generation in Source Code" is more of a feature for C# devs than VB.NET devs, as we (VB.NET) have the 'Handles' keyword and have not had to explicitly wire up server side events in source for as long as I can remember. Events can be selected to auto-generate in code by selecting them from the dropdowns above the source editor without ever having to go to the page's source. Regardless still very nice enhancements MSFT and looking forward to hearing about more in the future!

  • will we be able to download the Visual Studio vNext through DreamSpark as student?

  • So, the markup view is going to become as slow as the designer?
    Bad news...

  • That is pretty nice scott. I think that changing designview to codeview makes a kind of "lost context" so a developer slows productivity.

    Nice catch

  • These changes will drastically improve my day-to-day coding tasks. Thank you!!

  • Hi Scott Glad to see you blogging again.

    Now few things. I was sure that few months ago you moved for good to the Azure team. Now it looks like you're still in charge of .Net. Can you clarify what is your role now, as I can see you're starting a new ASP.NET series?
    Also I like the idea of new features, but can Microsoft fix the IDE first? Since the move to WPF for the editor, it's cripled and it is very very slow.
    When you look at a demo, seems to be ok. But in real world with thousand of lines of code it's really bad.
    VS 2010 crash also a LOT! Don't know hwy exactly, maybe because it is behind in terms of code or something else, but this need to be addressed soon!
    I like also to see minor things fixed like the broken Intellisense with JQuery VS docs, giving fals errors at the opening of a project.
    Don't take it wrongly, I love new stuff but I prefer to see the existing ones fixed first :-)

    Cheers
    Paschal

  • But WebForms is dead :)
    At least is should be.

  • Hi Scoot,

    This is new feature is grate, I expected this feature since VS2008.

    But how long we need to wait for this new feature?

    Is vNext a complete new version of ASP.NET and Visual Studio, or just a upgrade package?
    ASP.NET 5? or ASP.NET 4.5

    Can it be added as a plug-in to VS2010?

    Cheers

  • It looks very productive...

    Where can we download Visual Studio vNext for new stuff.

  • I wish this had been done 5 years ago!

  • @dm,

    >>>>>> By the way do the VS team plans to do anything about the more general issue, that when you select an element on the page and open the Properties windows for the first time, it will show the properties of the page instead of the element. Then you have to select the item again. It can be annoying when it happens for the 100th times a day.

    Can you send me email (scottgu@microsoft.com) about this issue? I can then loop you in with the team to investigate.

    Thanks,

    Scott

  • @Jonathon,

    >>>>>> One thing that has always frustrated me is the size of the glyph when intellisense is present - why is it so small? Its a very small target area on a big screen, especially at the end of a long day, or when you try to use somebody else's machine. Would it be possible to provide an option to make this bigger?

    That is a good question. I think the glyph we are using in source view is proportional to the text size in the editor. So if your text is bigger it will automatically be bigger too.

    Hope this helps,

    Scott

  • @Cori,

    >>>>>> Will dragging a usercontrol onto source view also work like it does in design view (registering the control & giving it proper uc tag markup) instead of just a path to it, like it does now in source view?

    I need to double check, but I believe that is supported now :)

    Thanks,

    Scott

  • @J,

    >>>>>> Visual Studio 2010 crashes often and IIE Express locks up DLLs all the time... The IDE itself is slow as hell. What's going on... I don't want new features. I just want it to do the basic functions extremely efficient and well. Is this too much to ask Microsoft??? I am trying to move to Sublime Text 2 + Vim mode and power shell script and hopefully with practice I can eventually replace VS... Not sure if this is just a dream..,

    You shouldn't be seeing those issues. If you can send me email (scottgu@microsoft.com) I can loop you in with the team to investigate.

    Hope this helps,

    Scott

  • @Tugberk,

    >>>>>> will we be able to download the Visual Studio vNext through DreamSpark as student?

    Yes - if you are in DreamSpark you get access to VS.

    Hope this helps,

    Scott

  • @Paschal,

    >>>>>>> Now few things. I was sure that few months ago you moved for good to the Azure team. Now it looks like you're still in charge of .Net. Can you clarify what is your role now, as I can see you're starting a new ASP.NET series?

    I am in Azure now, but also run a bunch of .NET and VS team too. ASP.NET, WCF, WF, AppFabric, Service Bus, IIS, BizTalk, WebMatrix and the VS tools for Web, Web Services and Workflow are all part of my team too.

    >>>>>> Also I like the idea of new features, but can Microsoft fix the IDE first? Since the move to WPF for the editor, it's cripled and it is very very slow. When you look at a demo, seems to be ok. But in real world with thousand of lines of code it's really bad. VS 2010 crash also a LOT! Don't know hwy exactly, maybe because it is behind in terms of code or something else, but this need to be addressed soon! I like also to see minor things fixed like the broken Intellisense with JQuery VS docs, giving fals errors at the opening of a project.

    Send me email (scottgu@microsoft.com) with details of the problems and we can have someone help investigate.

    Hope this helps,

    Scott

  • re: glyph size

    Would it be possible to make it configurable anyway? I know a couple of devs with disabilities who cannot use it as their use of the mouse is not as precise as others. Even if it was a registry hack :)

    Jonathan

  • expecting Sooon

  • If I see someone using Design View or Smart Tags I automatically consider them a complete idiot and would never trust them to touch my code or any projects I work on, these features are for the sub-par developer, which help Microsoft make money but also adds to the ever increasing morons in our industry.

  • This is a great feature that will save a lot of time to everyone. Welcome back Scott!

  • Thanks Scott for your time and answering my question.

  • Gr8 improvement , this is another one of "must to" features I was wating for years.

  • Hi Scott , i love this features. i have used the framework in 3.5 but right now it is not in visual studio it is available in latest 3.5 framework...

  • Event handler and set properties of grid's template is really nice one, this is really nice once where we have to define any event from aspx page.

  • Hi Scott,
    HTML Editor Smart Tasks is a helpful thing.
    I thing there will be another helpful feature if user can select an appropriate portion of html code and convert it to a User Control automatically.
    Do you have any plan to do something like this?

  • @Jonathan,

    >>>>>> Would it be possible to make it configurable anyway? I know a couple of devs with disabilities who cannot use it as their use of the mouse is not as precise as others. Even if it was a registry hack :)

    I forwarded your suggestion to the team for them to look at.

    Thanks!

    Scott

  • @Majid,

    >>>>>> I thing there will be another helpful feature if user can select an appropriate portion of html code and convert it to a User Control automatically. Do you have any plan to do something like this?

    Yep - we are going to enable that too! :-)

    Thanks,

    Scott

  • these are really cool features.... More of like the silverlight features.....

  • Wiring up events from code is very useful for me. I use Telerik's controls, and sometimes I don't have the right version installed for "design-time" support, but still need to add new events. In this case you get errors in design-view, so you can't use the lightning bolt way. This will solve that. Thanks!!

  • Wow its a cool feature

  • Very cool stuff, I can see lots of time saved using these techniques... Every time I'm working with somebody new to ASP.NET, it's always been a pain to explain how/why data bound elements are not evaluated until run-time.. and how they must test (run) their code to find run-time bugs that maybe have occurred while typing. I'm also very happy to hear that HTML Source Editor is finally getting some attention, I've always hated having to do split view, going to the WYSIWYG and clicking a control to generate event handler or access the smart tasks...

  • In the piece of news found by Mietanfrage I learned that police in Devon and Cornwall have threatened to shut down pubs that fail to control customers smoking outside. Officers say there are problems with customers taking drinks outside in local no-alcohol zones.
    They also complain that people are blocking the streets, particularly at the weekend. Licensees were warned of the police concerns at a recent pubwatch meeting and some pubs were sent individual letters.

  • Maybe completely off topic, but have you noticed that your blog is still showing Steve Sandersons MVC V2 book on the right hand side of the page (under "News")? His newer edition for MVC3 is now available, and I believe quite good.
    ps no, this is not Steve :-)

  • It's so good. When it will release?

  • Asp mi? Php mi?

  • Its great Scott.Thanks for wonderful narration.

  • Great stuff
    Thanks for sharing it!

Comments have been disabled for this content.