Set default button

  • Thread starter Thread starter Lou Civitella
  • Start date Start date
L

Lou Civitella

How can I set a button as default on an aspx page? When the user hits the
Enter button this default button is automtcally clicked.

Thanks,
Lou
 
In ASP.NET 2.0 the panel control has a new DefaultButton property.
Set this property to the ID of a button control and it will be the default
button when focus is in that panel.
 
Hi,

To your TextBox add a JavaScript event onkeydown using
Attributes.Add().
if pressed key is EnterKey i.e with KeyCode=13 then call the Click()
method of the button(this is the default button)


TextBox1.Attributes.Add("onkeydown", "if(event.keyCode){if
(event.keyCode == 13)
{document.getElementById('"+Button1.UniqueID+"').click();return
false;}} else {return true}; ");

thanks,
aru
 
Back
Top