Asp.Net形式DefaultButton错误在Firefox [英] Asp.Net Form DefaultButton Error in Firefox

查看:198
本文介绍了Asp.Net形式DefaultButton错误在Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.NET中产生code为用DefaultButton属性设置窗体中包含的JavaScript不佳,使功能在IE工作,但不能在其他浏览器(Firefox specifcially)。

The .Net generated code for a form with the "DefaultButton" attribute set contains poor javascript that allows the functionality to work in IE but not in other browsers (Firefox specifcially).

命中enter键确实与所有浏览器提交表单,但是当它发生在一个与LT的的Firefox不能忽视的关键preSS; textarea的>控制。结果是一个多行文本区域控制不能为多在Firefox的回车键提交表单,而不是创建一个新的行。

Hitting enter key does submit the form with all browsers but Firefox cannot disregard the key press when it happens inside of a <textarea> control. The result is a multiline text area control that cannot be multiline in Firefox as the enter key submits the form instead of creating a new line.

有关错误的更多信息,请这里阅读

For more information on the bug, read it here.

这可能是固定在Asp.Net 3.0 +但有解决方法仍然有2.0创建。

This could be fixed in Asp.Net 3.0+ but a workaround still has to be created for 2.0.

最轻的解决方法(一黑客工具,看起来并不像一个黑客= D)任何想法?在上面的链接的解决方案,让我害怕一点点,因为它可以很容易产生意想不到的副作用。

Any ideas for the lightest workaround (a hack that doesn't look like a hack =D)? The solution in the above link scares me a little as it could easily have unintended side-effects.

推荐答案

我用这个功能改编自codeSTA。

I use this function adapted from codesta.

的http://博客。codesta.com / codesta_weblog / 2007/12 /净陷阱--- p.html

您通过像这样一个div周围的code使用它。你可以继承的形式自动包括这一点。我不使用它那么多,所以我没有。

You use it by surrounding your code with a div like so. You could subclass the Form to include this automatically. I don't use it that much, so I didn't.


<div onkeypress="return FireDefaultButton(event, '<%= aspButtonID.ClientID %>')">
    (your form goes here)
</div>

下面的功能。


function FireDefaultButton(event, target) 
{
    // srcElement is for IE
    var element = event.target || event.srcElement;

    if (13 == event.keyCode && !(element && "textarea" == element.tagName.toLowerCase())) 
    {
    	var defaultButton;
    	defaultButton = document.getElementById(target);

    	if (defaultButton && "undefined" != typeof defaultButton.click) 
    	{
    		defaultButton.click();
    		event.cancelBubble = true;
    		if (event.stopPropagation) 
    			event.stopPropagation();
    		return false;
    	}
    }
    return true;
}

这篇关于Asp.Net形式DefaultButton错误在Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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