ITKeyword,专注技术干货聚合推荐

注册 | 登录

jquery - How can I disable the DefaultButton of an asp:Panel at ClientSide?

itPublisher 分享于

2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1062

2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址https://www.aliyun.com/minisite/goods

up vote 1 down vote favorite 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 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 DefatulButton 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 ? jquery asp.net javascript-events panel preventdefault
  |
  this question asked Aug 3 '11 at 12:18 teenup 2,905 6 41 92



 |  2 Answers

up vote 1 down vote ---Accepted---Accepted---Accepted---

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!
  |
  this answer answered Aug 3 '11 at 12:46 Dan Diplo 20.5k 3 41 72      I already solved the problem before I looked up this solution, through some alternate way, but this is the exact answer of my question. Therefore +1 and ---Accepted---Accepted---Accepted---

as answer. –  teenup Aug 3 '11 at 17:48      this did not work in my case. –  Nathan Tregillus Jun 18 '13 at 23:40



 |  Did you find this question interesting? Try our newsletter Sign up for our newsletter and get our top new questions delivered to your inbox (see an example). Subscribed! Success! Please click the link in the confirmation email to activate your subscription. up vote 0 down vote 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.
  |
  this answer answered Aug 3 '11 at 12:31 Mantorok 2,490 2 15 26

 | 

up vote 1 down vote favorite 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

相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。