如何在客户端禁用 asp:Panel 的 DefaultButton?
我有一个 asp:Panel
,其默认按钮设置为表单的保存 按钮。但我希望当焦点位于表单中的一个特定锚元素上时,Enter 键不应触发面板的DefaultButton。相反,它应该触发在锚点的 href
内编写的 Javascript 函数,如果我只是从表单中删除 asp:Panel
,它就可以完美工作。
我尝试了很多解决方案,但似乎都不起作用。其中一些是:-
我捕获锚点的 focus 事件,其中我为 keypress 事件挂钩另一个处理程序并使用
event.preventDefault()< /code> 以便仅在那里取消该事件,并删除锚元素的
blur
上的该keypress
事件。但这并不能阻止Panel的DefaultButton
被执行。在外部 Panel 内使用另一个
asp:Panel
并将其DefaultButton
设置为ImageButton
以替换锚点元素(因为我们无法将DefaultButton
设置为锚点)。 - 但这仍然会触发外部面板的DefaultButton
。
我需要的是某种方法来禁用客户端外部 asp:Panel
的 DefaultButton
。这可能吗?
I have an asp:Panel
whose default button is set to Save button of the form. But I want that when the focus is on one specific anchor element in my form, the Enter key should not fire the DefaultButton of Panel. Rather it should fire the Javascript function written inside the href
of the anchor, which perfectly works if I just remove the asp:Panel
from the form.
I have tried many solutions, but none of them seems to work. Some of them are:-
I capture the focus event of anchor in which I hook another handler for keypress event and use
event.preventDefault()
so that event is cancelled there only and remove thatkeypress
event on theblur
of anchor element. But this does not stop theDefaultButton
of Panel from being executed.Use another
asp:Panel
inside the outer Panel and set itsDefaultButton
to theImageButton
which replaces the anchor element(because we can not setDefaultButton
to anchor). - But this still fires theDefaultButton
of the outside Panel.
What I need is some way to disable the DefaultButton
of the outer asp:Panel
at the Client Side. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不太确定你在做什么,但是当你向
asp:Panel
添加 DefaultButton 属性时,它会向渲染的 div 添加如下内容:你可以使用 jQuery 删除该属性,方法如下:
(假设您的面板的 ClientID 是
Panel1
)。希望这对您有所帮助!Not quite sure what you are doing, but when you add a DefaultButton attribute to an
asp:Panel
then it adds something like this to the rendered div:You can remove that attribute using jQuery by doing something like:
(Assuming the ClientID of your Panel is
Panel1
). Hope that is of some help!听起来您在使用 asp.net 控件生成 Javascript 时遇到了典型的限制。
我会编写您自己的函数来处理此表单的提交,然后将必要的逻辑放入其中。
It sounds like you are hitting a typical limitation when using the asp.net controls to generate Javascript.
I would write your own function to handle the submission of this form and then put the necessary logic inside of that.