开发者

ASP.Net multiple forms on same page and the 'enter' key

I have an ASP.Net site that is using the singular form model. Each page has multiple forms (login, sea开发者_开发知识库rch), and I'd like for the forms to obey the 'enter' key. Currently if a user is in the login form at the top of the page, if they hit 'enter' the form is submitted, but if they are in the search form, a little further down the page (and lower in the DOM), hitting 'enter' causes the login form to submit.

Can someone point me int he right direction re: handling this?


Found the solution without needing any client-side code:

http://forums.asp.net/t/985791.aspx/1?ASP+NET+2+0+Enter+Key+Default+Submit+Button

Basically, I wrap the 'form' in an asp:Panel, and set the DefaultButton property to the id of the button I want the enter key to trigger.


You set the default button at the form level. Which means if you do a onFocus you can programmatically change the default button (when the enter key is hit). This would allow you to accept enter on the search form when they are using it and on the login form when they are using that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜