如何禁用提交ASP的行为:ImageButton的? [英] How to disable submit behaviour of asp:ImageButton?

查看:528
本文介绍了如何禁用提交ASP的行为:ImageButton的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在它可以在鼠标点击触发一个页面一个图像按钮,默认情况下它被上输入preSS也是我要禁用触发。

I have a image button in a page which can be triggered on mouse click, by default it gets triggered on enter press also which i want to disable.

我知道在ASPUseSubmitBehaviour属性:按钮,有没有办法做同样在ASP:ImageButton的

I know about "UseSubmitBehaviour" attribute in asp:Button, is there a way to do the same in asp:ImageButton?

推荐答案

我会假设你有某种输入控件,你不想要一个回车键preSS自动提交当用户意外击中进入键。如果是这样你可以一个javascript安其preSS事件附加到要禁用此行为为每个控制。

I will assume you have some sort of input controls and you don't want an enter keypress to auto submit when a user accident hits the enter key. If so you can attach a javascript onkeypress event to each control that you want to disable this behavior for.

function disableEnterKey(e)
{
     var key;
     if (window.event) key = window.event.keyCode; // Internet Explorer
     else key = e.which;

     return (key != 13);
}

// In your aspx file Page_Load do the following foreach control you want to disable
// the enter key for:
txtYourTextBox.Attributes.Add("OnKeyPress", "return disableEnterKey(event);");

如果你需要禁用完全回车键提交表单。情况下使用的onkeydown处理器上<车身方式> 在页面上标记

If you need to disable the Enter key submitting form completely. case use the OnKeyDown handler on <body> tag on your page.

JavaScript的code:

The javascript code:

if (window.event.keyCode == 13) 
{
    event.returnValue = false; 
    event.cancel = true;
}

与jQuery这将是更清洁,更容易和推荐的方法。你可以提出延期使用:

With JQuery this would be much cleaner, easier and the recommended method. You could make an extension with:

jQuery.fn.DisableEnterKey =
    function()
    {
        return this.each(function()
        {
            $(this).keydown(function(e)
            {
                var key = e.charCode || e.keyCode || 0;
                // return false for the enter key
                return (key != 13);
            })
        })
    };

// You can then wire it up by just adding this code for each control:
<script type="text/javascript" language="javascript">
    $('#txtYourTextBox').DisableEnterKey();
</script>

这篇关于如何禁用提交ASP的行为:ImageButton的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆