Enter key on ASP.NET 2.0 forms

One piece of functionality that is often requested is the ability to submit a web form using the <enter> key. In some cases, you may need multiple textbox controls to submit differently by defaulting to different buttons. In the past there have been various javascript hacks to ensure this works successfully, but in ASP.NET 2.0 there is a simpler function.

By setting the defaultbutton property on a form or – even better – an <ASP:Panel> control, the page automatically handles it for you. Each set of controls which should submit with a certain button can be contained in the panel and everything is hooked up automagically.

One caveat: If you set a default button on a panel but not in the form, other controls seem to use the panel’s default button even when they are not in the panel.

Posted on December 4, 2006 in .NET. Add comment   

No Comments

(Comments are moderated.)