Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET WebForms
How to Fire Button Click Event when Enter key is pressed after writing some text in textbox.
 
<form id="form1"  runat="server">
    <div>
    
    Enter text-<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Send" Width="65px" />
    
    </div>
    </form>
 
Posted 27-Feb-13 2:03am
Edited 27-Feb-13 2:06am
v2
Comments
Sm.Abdullah at 27-Feb-13 8:49am
   
why do not you put your click event code in side a function and call that function after detecting the enter key against a textbox ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Set these properties of Form you will get your goal
 <form id="Form1">
        defaultbutton="SubmitButton"
        defaultfocus="TextBox1"
        runat="server"></form>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Refer this thread
http://stackoverflow.com/questions/268588/call-a-specific-button-onclick-event-when-the-enter-key-is-pressed-c-sharp[^]
 
It's quite easy and there can be many ways to do that, Google and see, u will find so many results
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Try this
 

<script type="text/javascript">
function enterEvent(e) {
if (e.keyCode == 13) {
$("input[id=Button1]").click();
}
}
</script>
<asp:textbox id="TextBox1" onkeydown="javascript:enterEvent(event);" runat="server" xmlns:asp="#unknown">
 
<asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" xmlns:asp="#unknown" />
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

 
 

<script type="text/javascript">
function FireOnClickButton() { 
document.getElementByID("Button1").click();
 
}
</script>
<asp:textbox id="TextBox1" onkeypress="FireOnClickButton();" runat="server" xmlns:asp="#unknown">
 
<asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" />
 

hopes this work for you...
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Take all your page contains in a panel and set DefaultButton property to your submit button.
<asp:panel runat="server" id="pnlSrchQuote" defaultbutton="btnSearch" xmlns:asp="#unknown">
     <!--My Controls here-->
</asp:panel>
 
--Amit
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,212
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100