在表单中prevent ASP.NET文本框从提交表单 [英] Prevent ASP.NET textbox within a form from submitting the form

查看:132
本文介绍了在表单中prevent ASP.NET文本框从提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我工作的页面:

http://mcstevenswholesale.com/catalog.aspx

目录下面的文本框,您可以跳到目录中的某个特定页面。但是,如果你打在文本框中输入,而不是点击开始按钮,提交在左上栏的搜索功能。我想这是因为整个页位于一个ASP表单中,但我没有与右侧的电子邮件注册框同样的问题。

The textbox below the catalog allows you to skip to a specific page in the catalog. However, if you hit enter in that textbox rather than clicking the "Go" button, it submits the search function in the upper left column. I thought this would be because the entire page is located within an ASP form, but I don't have the same problem with the email signup box on the right side.

我试图把页码文本框变成自己的HTML表单,并试图改变按钮图像,按钮,提交输入项目。这些都没有奏效。我不想重新加载页面,该页面中翻转。我是相当新的ASP,所以我很抱歉,如果我做一个很明显的错误。

I have tried putting the page number textbox into its own HTML form, and have tried changing the button to an image, a button, and a submit input. None of these have worked. I don't want the page to reload, just the page to flip. I'm fairly new to ASP, so I'm sorry if I'm making a very obvious mistake.

这里的code的页码文本框(GotoPage记述是一个JS函数,翻转目录页):

Here's the code for the page number textbox (goToPage is a JS function that flips the catalog page):

<div id="goToPage">
    Go to Page: 
    <input id="pageTextbox" type="text" onkeydown="if (event.keyCode == 13) goToPage();"></input>
    <a onclick="goToPage()" href="#"></a>
</div>

本的onkeydown使得页面变化工作,但它仍是起火的搜索功能。如何从这样做prevent呢?

The onkeydown makes the page change work, but it still fires the search function. How do I prevent it from doing that?

推荐答案

回车键的默认行为是提交当前表单中大部分(如果不是全部)的浏览器。

The default behavior of the enter key is to submit the current form in most (if not all) browsers.

您需要燮preSS回车键的默认行为。共进晚餐preSS默认行为的正确方法是让事件处理程序的返回false

You need to suppress the enter key's default behavior. The proper way to suppress the default behavior is to have the event handler return false.

如果GotoPage记述()返回false最简单的办法是:

If goToPage() returns false the simplest solution is the following:

的onkeydown =如果(event.key code == 13)返回GotoPage记述();

onkeydown="if (event.keyCode == 13) return goToPage();"

如果没有你可以调用GotoPage记述()之后添加返回FALSE;

If not you can add return false after the call to goToPage();

的onkeydown =如果(event.key code == 13){GotoPage记述();返回false}

onkeydown="if (event.keyCode == 13) { goToPage(); return false} "

这将导致回车键不提交表单时$ P $页码文本框中pssed。如果要禁用它整个页面看到以下内容:

That will cause the enter key to not submit the form when pressed within the page number text box. If you want to disable it for the entire page see the following:

  • http://webcheatsheet.com/javascript/disable_enter_key.php
  • https://stackoverflow.com/questions/6017350/i-need-javascript-function-to-disable-enter-key

这篇关于在表单中prevent ASP.NET文本框从提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆