tags:

views:

59

answers:

4

Hi, 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.redirect("result_recherche.aspx?mot_cle=" & box_mot.Text)
    End Sub
</script>
A: 

Did you try the onLostFocus event instead of onClick ?

Trefex
No action with thi event
bahamut100
+3  A: 

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()

  }

});
Andi
Run out of votes today. Will upvote tomorrow.
Daniel Dyson
Cheers Daniel :)
Andi
+1  A: 

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

Derek Hunziker
it works, thanks :)
bahamut100
I thought you wanted a Enter key trigger so not sure how this solved the problem? Curious to know :)
Andi
A: 

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.

Shane N