Submit a form by pressing the enter key

C

Chinnala

All,

I have a "Search" button and "Cancel" button on a web page. When I hit
enter, the "Cancel" button receives the focus and btnCancel event is
fired. But I want the search button event to be fired when I click
enter ? How can I implement this? Appreciate your replies.

Thanks,
Chinnala.
 
M

mank1327

I think either

<form id="form1" runat="server" defaultbutton="">

or

<form id="form1" runat="server" defaultfocus="">

with the empty value being the id of your search button.
 
G

Gaurav Vaish \(www.Edujini-Labs.com\)

It's defaultButton='idOfTheButton'

I would suggest using the following code in Page_Load or whereever your
logic is appropriate:

base.Page.Form.DefaultButton = buttonID.UniqueID;

rather than directly using

<form defaultbutton='buttonID' ..>

unless your button is directly within the form.

If your button is inside a UserControl or a datagrid / gridview etc, use
UniqueID (value of ID attribute on the client side) to get the correct id
which may or may not be same as the value of the property ID.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top