Dot Net Lover

Tuesday, November 27, 2007

Enter Key Solutions in ASP.net - MUST READ

hi! Friends
Many times u must have faced a problem with ASP.net Form on making the Default Buttons...
(submit a form when visitor hit an Enter key... )
Suppose we have two submit buttons on a Page

1. In the Master Page - Infront of a Search TextBox - "GO" Button
2. In the Content Place Holder - Below a Login Form - "Login" Button

Now the problem is u can make only one default defaultbutton out of these two????
But what if u need to make both????

Below is the Code enabling u to do the Same....

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}; ");


Just write this Code on as many as TextBox Controls u want. This way you can "connect" as many text boxes and buttons as you want.

Happy Coding :)

0 Comments:

Post a Comment

<< Home