473,378 Members | 1,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Fire button click on enter key press

In my web page i have one textbox and a button...and my requirement is soon i type the text in the text box and press enter key,the button code should get fired...im designing my web page in asp.net with c# code


thanks
Dec 29 '08 #1
4 21652
PRR
750 Expert 512MB
@satyabhaskar
Use following javascript
Expand|Select|Wrap|Line Numbers
  1. function fun1(e, button2){
  2.       var evt = e ? e : window.event;
  3.       var bt = document.getElementById(button2);
  4.       if (bt){
  5.           if (evt.keyCode == 13){
  6.                 bt.click();
  7.                 return false;
  8.           }
  9.       }
  10. }
  11. //And on the textbox 
  12. TextBox1.Attributes.Add("onkeypress", "return fun1(event,'" + Button1.ClientID + "')");
  13. //Button1 is the button whose onclick you will call when enter is pressed on TextBox1
  14.  
Use technical sounding title for your thread..
Dec 29 '08 #2
Frinavale
9,735 Expert Mod 8TB
You could try using the "DefaultButton" property of a Panel...

Place your TextBox and your Button inside a Panel and then set the Panel's "DefaultButton" property to your button. Any time the user is within that panel and they hit the enter key that button will be used to submit the page.

For example:

Expand|Select|Wrap|Line Numbers
  1. <asp:panel id="content" runat="server" DefaultButton="myDefaultButton">
  2.     <asp:TextBox id="myTextBox" runat="server"></asp:TextBox>
  3.     <asp:button id="myDefaultButton" runat="server" text="default button" />
  4. </asp:panel>
The button with the id of "myDefaultButton" will be used to submit the page when the user is in the "content" panel.

I think there is a DefaultButton for the page or body as well....can't remember at this time though.

-Frinny
Dec 29 '08 #3
It's working..Good Job....
Sep 12 '14 #4
Thanks. After searching through a kazillion threads, this finally worked.
Oct 19 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Dan | last post by:
Consider a simple form with a textbox and button. Is there a way to handle the common situation where a user presses "return" rather than clicks on the button. I can already detect the...
11
by: CW | last post by:
I have message entry screen that's causing me a bit of an issue. At the moment, there are 2 buttons, one is used to send message to another user (btnSend) and another is used to send messages to...
3
by: N. Shehzad | last post by:
This button click is fired for first time, but does not get fired for second time if I click. It again fires 3rd time, but not 4th time and so on.. I want to button to be fired everytime. I want...
12
by: SJ | last post by:
Hope someone can help me out there I'm struggling with a particular problem... I have a form with many tab pages. On one tab page I've got a button which when clicked with a mouse adds items...
5
by: Dundealing | last post by:
I have a single button on my form, and when I press the Enter key while a TextBox has focus I want the Button.Click event to fire. Is there a simple way to do this ?
17
by: Eric | last post by:
I'm new to JavaScript and I wrote this code to play with. Oddly, if I enter text in a box and then press the button, I only get the onChange event for the text box and not the button's onclick...
0
by: nraji | last post by:
hi, I have designed a web part using VS 2003 (Web control library template). I need to publish that in share point. Its not like drag and drop the things from toolbar. Every thing I need to do in...
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
5
by: =?Utf-8?B?Umljaw==?= | last post by:
I have a form FormA with a button Button1; I use SetParent(FormB.Handle, this.Handle) to load FormB inside FormA. FormB also has a button Button1 which displays a messagebox. When Button1 is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.