473,466 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Submit a form by pressing the enter key

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.

Jan 9 '07 #1
3 1256
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.

Jan 10 '07 #2
Likely You Cancel button is located before the Search one. Pressing the
Enter is equal to clicking the first button on the form. The simplest
solution would be to swap the buttons around.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Chinnala" <pc*******@gmail.comwrote in message
news:11**********************@i39g2000hsf.googlegr oups.com...
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.

Jan 10 '07 #3
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.

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
"mank1327" <mc*********@hotmail.comwrote in message
news:8F**********************************@microsof t.com...
>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.

Jan 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ivanhoe | last post by:
All articles and tutorials I've seen on subject of forms say that if there's name and value for submit button(input tag with type="submit"), they'll get submitted along with the rest of the...
15
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and...
1
by: jrefactors | last post by:
When the user type something in text box, and press enter, it will submit the form data to test2.jsp, even without pressing submit form button. This is not what I want, I want to submit the form...
8
by: bettina | last post by:
I want to submit a form but without a submit button. That's to say, I want that by giving a definite code in a field and then press <ENTER> the form will be submitted. For Example <form...
5
by: Dennis Allen | last post by:
Hi. I have a user who wants his form submitted when he presses . Is it possible? If so, how?
4
by: Jerry | last post by:
Hello I have some textboxes (input type=Text) in a Form. In some Forms if I Press Enter while I am in the Textbox It causes a Submit. The input type is text not submit. It's obsure that the...
10
by: Perry van Kuppeveld | last post by:
Hi, I have a problem with formatting a table including text fields wich can contain up to 255 chars. I need a table with 3 columns: - First column 50 % over the with a rowspan of the total...
7
by: David T. Ashley | last post by:
Hi, For a web page, I want a SUBMIT button that commits the form data and a CANCEL button that goes to a different target (i.e. a different script). I haven't figured out how to do this,...
24
by: MichaelK | last post by:
Who knows how to prevent submitting a form on the press Enter button before all fields on the form are filled up. People just enter the first field hit Enter and it submits the form and doing...
9
by: learning | last post by:
Hi! Here's my situation: I have one textfield with one 'submit' button in PAGE1.PHP. When I click on the 'submit' button I am sent to PAGE2.PHP where I have a "switch" routine that checks...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.