So I have a page, it had multiple textboxes, linkbuttons, and buttons. Currently, a user clicks a linkbutton "Edit" which allows them to enter data in that row, via textboxes. However, upon pressing enter, the event for one of the buttons fired...this is not desired at all. Apparently, this is the default behavior built in?

Is it possible to associate each textbox so that pressing enter will act on a specific assigned linkbutton or button, without the textboxes being in separate forms?

If this is not possible, I'm going to try and create a button and make it the default form button, but disable and hide it, so that pressing enter submits nothing.

Thanks!

有帮助吗?

解决方案

You can set the UseSubmitBehavior property to "false" on a Button control. This will cause the button to be rendered as an <input type="button" /> tag instead of an <input type="submit" /> tag. As a result, pressing the Enter key will not cause the button to be pressed, unless the button actually has the focus.

<asp:Button runat="server" UseSubmitBehavior="false" ... />

其他提示

You can override the KeyPress event for each textbox to catch the enter key and then fire the code for the corresponding button.

if(e.KeyChar == '\n') 
   // execute button code

you can put them in separate panels and use the defaultbutton attribute to tell the panel which button to use when enter is pressed.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top