Preventing a button from responding to 'Enter' in ASP.net

Posted by kd7iwp on Stack Overflow See other posts from Stack Overflow or by kd7iwp
Published on 2010-05-13T23:32:05Z Indexed on 2010/05/13 23:44 UTC
Read the original article Hit count: 271

Filed under:
|
|

I have a master template that all the pages on my site use. In the template there is an empty panel. In the code-behind for the page an imagebutton is created in the panel dynamically in my Page_Load section (makes a call to the DB to determine which button should appear via my controller).

On some pages that use this template and have forms on them, pressing the Enter key fires the click event on this imagebutton rather than the submit button in the form. Is there a simple way to prevent the imagebutton click event from firing unless it's clicked by the mouse? I'm thinking a javascript method is a hack, especially since the button doesn't even exist in the master template until the button is dynamically created on Page_Load (this is ugly since I can't simply do <% =btnName.ClientId %> to refer to the button's name in my aspx page).

I tried setting a super-high tabindex for the image button and that did nothing. Also set the button to be the DefaultButton in its panel on the master template but that did not work either.

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET