Setting the Default Button in ASP.Net 1.1

Q: I have an ASP.Net 1.1 search form with several buttons on it (Search, Clear, Logoff) and a search word field. Currently, if the user enters text in the "Search Word” fields, and presses ENTER, the logoff button (located on the banner at the top of the form) is activated and the user is prompted if he wants to logoff. How can I change it so the ENTER key will activate the “Search” button instead? In other words, how can I make the “Search” button, the default button?

A: In ASP.Net the enter button executes the first button on the page. So create a button that is not visible (width is set to 1 px) and placed it at the top of the page before the logoff button. Change the background color if needed and make sure it cannot be seen. Then set the click event in .aspx page to execute the search button click event. When the user presses enter, the first button is executed and it will call the search method.

Comments

Popular posts from this blog

Working with double quotes (") in VB.Net

Using VB Script to display part of an IP address

Object reference not set to an instance of an object when using HTMLEditorExtender