Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Saturday, September 02, 2006

Default button in ASP.NET (ASP.NET)

How to make a default button in ASP.NETWe need to specify exactly what button will be "cliked" when visitor press Enter key, according to what textbox currently has a focus. The solution could be to add onkeydown attribute to textbox control:TextBox1.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) 
|| (event.keyCode == 13))
{document.getElementById('"+Button1.UniqueID+"').click();return false;}} else {return true}; "); This line of code will cause that button Button1 will be "clicked" when visitor press Enter key and cursor is placed in TextBox1 textbox. On this way you can "connect" as many text boxes and buttons as you want.

Post a Comment