Handle Enter Key on Website (ASP and VB)

2019-08-05 10:40发布

So I have a website with multiple asp controls. When I press enter inside by login form, the search function runs because it's the first thing found on the page.

How would I handle the enter button so that when the active textbox is for the login form, the loginbutton code actually runs rather than the searchbutton.

One last problem is that the login controls are inside a loginview so the hierarchy shows that the asp:textbox and asp:button for logging in are inside 3 tags like so:

<loginview>
   <login>
      <logintemplate>
      //controls are here.
      </logintemplate>
   </login>

Just a note that all controls are asp and that all code is prefered in VB. Thanks

1条回答
贼婆χ
2楼-- · 2019-08-05 11:28

You want to set the default button on the form like this:

  Page.Form.DefaultButton = "LoginButtonId"

MSDN Docs: http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlform.defaultbutton%28VS.80%29.aspx

Also, see this question for an issue I had in Firefox related to this : Default Form Button in FireFox

查看更多
登录 后发表回答