The Enter button in ASP.NET
May 3rd, 2005 by alpriest
Taken from this blog is a technique which will postback the form when you hit enter. If you use the script below, it will work in any browser (although bypassing any onClick code for the button specified).
function clickButton(e, buttonid)
{
var bt = document.getElementById(buttonid);
if (typeof bt == 'object')
{
try
{
if(navigator.appName.indexOf("Netscape")>(-1))
{
if (e.keyCode == 13)
{
bt.click();
return false;
}
}
if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
{
if (event.keyCode == 13)
{
bt.click();
return false;
}
}
}
catch (er)
{
// invoke the default postback handler for buttons that render as tags
__doPostBack(buttonid,'');
}
}
}