开发者

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:-

  1. 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 that keypress event on the blur of anchor element. But this does not stop the DefaultButton of Panel from being executed.

  2. Use another asp:Panel inside the outer Panel and set its DefaultButton to the ImageButton which replaces the anchor element(because we can not set DefaultButton to anchor). - But this still fires the DefaultButton 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜