jquery - How can I disable the DefaultButton of an asp:Panel at ClientSide?
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
|
相关阅读排行
- 1JavaScript组件之JQuery(A~Z)教程(基于Asp.net运行环境)[示例代码下载]
- 2Asp.Net+Jquery.Ajax详解1-开篇
- 3MVC学习笔记之:ASP.NET MVC的客户端验证-jQuery.validate验证结合Model验证中的实现
- 4asp.net MVC3 + JQuery 的ajax简单使用
- 5JQuery插件中的treeview与asp.net mvc的结合使用实例(转)-附加自己的写法