enter key to call <asp:imagebutton> event

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

I'd like to trap the keypress event for the enter key and trigger a server
side imagebutton click event.

However,

Page.RegisterHiddenField( "__EVENTTARGET", btnSubmitTracking.ClientID );

I've also tried,

txtTrackingNumber.Attributes.Add("onKeyPress", String.Format( "if
(event.keyCode == 13) __doPostBack('{0}', 'parms')",
btnSubmitTracking.ClientID));

This doesn't work with imagebuttons. It works fine with linkbuttons and
buttons, but I need to use an image for a button. Or is there someother
control or way I can accomplish this.

-Randy
 
try nesting your image control in a hyperlink control --that should make the
image clickable.
<asp:hyperlink ...onkeypress="bla"><asp:image ...></asp:image></hyperlink>
 
Thanks. That might work too. What worked for me was to "return false;"
after calling __doPostBack in the onKeyPress event. For some reason, you
don't need this with asp buttons and asp linkbuttons.

-Randy
 
Back
Top