文本框会导致ASP.NET按钮回传 [英] TextBox causes Button Postback in ASP.NET

查看:153
本文介绍了文本框会导致ASP.NET按钮回传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET 2.0,测试在FF3和IE7。

ASP.NET 2.0, testing in FF3 and IE7.

当我从一个文本框中点击'进入'按钮对应的onclick事件的事件在页面第一的ImageButton被激发。如果我删除的图像按钮,它触发页面上的下一个ImageButton的onclick事件。

When I hit the 'enter' button from a text box the corresponding "OnClick" event for the first ImageButton in the page is fired. If I remove that image button, it fires the next ImageButton OnClick event on the page.

从Firebug控制台,如果我使用JavaScript来提交表单,这不会发生。但无论出于何种原因按回车键从文本框触发无关的ImageButton事件。

From the FireBug console, if I use JavaScript to submit the Form, this does not happen. But for whatever reason hitting enter from the textbox triggers the unrelated ImageButton event.

我发现<一个href=\"http://stackoverflow.com/questions/712407/textbox-on-gridview-causing-a-button-click-event-to-fire\">this问题其中有一个类似的问题,但所提出的问题的答案的解决方案不起作用,因为ImageButtons没有对他们的UseSubmitBehavior属性。

I found this question which had a similar problem, however the proposed answer to that solution doesn't work since ImageButtons do not have a "UseSubmitBehavior" property on them.

我不明白为什么这个事件被触发。如果我看的Request.Form,我可以看到__EVENTTARGET是空的,它实际上是发布整个表格的内容(我所有的文本框),还包括imageButton.x和imageButton.y键/值对。

I don't understand why this event is firing. If I look at Request.Form, I can see that __EVENTTARGET is empty, and it is in fact posting the entire form contents (all of my textboxes), but also includes imageButton.x and imageButton.y key/value pairs.

这是为什么?我想我可以检测来自与JavaScript这些文本框ENTER键presses,但我过去的经验是这种行为是浏览器之间高度可变的。有什么建议?

Why is this? I suppose I could detect "enter" key presses from these text boxes with javascript, but my experience in the past is this behavior is highly variable between browsers. Any suggestions?

推荐答案

您可以尝试在ASP面板或窗体上设置默认按钮。这将让你控制,当用户点击回车键时会发生什么。

You could try setting a default button in an asp panel or on your form. This will let you control what happens when a user hits the enter key.

这篇关于文本框会导致ASP.NET按钮回传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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