开发者

How to execute a function when "Enter" is pressed?

开发者 https://www.devze.com 2023-01-06 16:01 出处:网络
I work on an old aspx website, and I should to debug some things. I would like to execute a function when the Enter touch is pressed, how do I do it ?

I work on an old aspx website, and I should to debug some things.

I would like to execute a function when the Enter touch is pressed, how do I do it ? The onClick on the imagebutton is working, but I don't know how to do it when you push Enter after typing a text in the textbox

<td>
<asp:TextBox ID="box_mot" Text="Entrez un mot-clef ou le nom d’un professionnel " runat="server" style=" border:0px ;color:#OOOOOO;font-family: arial;font-size:10px; height:16px; width:260px"/>
<asp:ImageButton ID="ImageButton1" ImageUrl="img_menu/bt_ok_gris.gif" runat="server" OnClick="rech"/>
</td>

And this is the code of the function :

<script runat"server">
    Sub rech(Src As Object, E As System.Web.UI.ImageClickEventArgs)
    response.redi开发者_高级运维rect("result_recherche.aspx?mot_cle=" & box_mot.Text)
    End Sub
</script>


You could use JQuery and the following tidy method:

$('#input_text').keyup(function(e) {
  if(e.keyCode == 13) {

    alert('Enter key was pressed.'); // or in your case call rech()

  }

});


Better to wrap your textbox and imagebutton with an asp:Panel and set it's DefaultButton attribute to "ImageButton1"


Did you try the onLostFocus event instead of onClick ?


You're trying to invoke server side (asp) code at a client site event. You have to keep in mind that server site code runs on the server, and client site code (javascript) run on the browser. So, the quick answer is you can't invoke your aspx code upon enter click.


Enter any thing in Text box then press Enter to execute

<form onSubmit='alerttest(this); return false'>        
    <input type="text">         
</form>


<script language="javascript">
    function alerttest()
    {
        alert("Executing jolly.exe !!!!");
        // function edited by Inderpreet singh
    **strong text**
 </script>
0

精彩评论

暂无评论...
验证码 换一张
取 消