How can I disable the DefaultButton of an asp:Panel at ClientSide?
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开发者_如何学C 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?
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:
onkeypress="javascript:return WebForm_FireDefaultButton(event, 'Button1')"
You can remove that attribute using jQuery by doing something like:
$("#Panel1").removeAttr("onkeypress");
(Assuming the ClientID of your Panel is Panel1
). Hope that is of some help!
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.
精彩评论