Die*_*ego 26 javascript asp.net internet-explorer-10
看起来ASP.NET 4.0还没有准备好处理由Internet Explorer 10触发的ImageButton事件.问题是IE10将图像点击坐标作为双值(带小数)发送,ASP.NET试图将它们解析为整数,呈现以下类型的错误:
System.Web.HttpUnhandledException (0x80004005):
Exception of type 'System.Web.HttpUnhandledException' was thrown.
---> System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Web.UI.WebControls.ImageButton.LoadPostData(String postDataKey, NameValueCollection postCollection)
at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.members_addtocartlogin_twostep_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\932deaba\63ff7eeb\App_Web_MyPage.aspx.28424a96.oraym_un.0.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Run Code Online (Sandbox Code Playgroud)
谷歌搜索,有些人建议强迫IE10在兼容性视图中运行.但是,添加元标记<meta http-equiv="X-UA-Compatible" content="IE=10" />并不能解决任何问题; 并且<?xml version="1.0" encoding="UTF-8">之前添加<!DOCTYPE>也不起作用.
有解决方案吗 我可以用Javascript捕获click事件并以某种方式删除小数?
注意:升级到Framework 4.5并重新编译可修复该错误.无需更改运行时版本,因为它仍然是4.0.
小智 22
有一些针对.NET CLR 2.0和4.0的修补程序,如Scott Hanselmann的博客文章中所述:
修复程序的作用是使用这些浏览器定义的新版本和未来版本更新\ Windows\Microsoft.NET\Framework \\ Config\Browsers中的ie.browser和firefox.browser文件.没有其他因素受到影响.
.NET 4
.NET 2.0
http://support.microsoft.com/kb/2600100 for Win7 SP1/Windows Server 2008 R2 SP1,Windows Vista/Server 2008,Windows XP/Server 2003
http://support.microsoft.com/kb/2608565 for Win7/Windows Server 2008 R2 RTM
或者,有一个基于客户端的javascript补丁(最初发布为Connect项目的变通方法,错误ID:755419):
$(function () {
// Patch fractional .x, .y form parameters for IE10.
if (typeof (Sys) !== 'undefined' && Sys.Browser.agent === Sys.Browser.InternetExplorer && Sys.Browser.version === 10) {
Sys.WebForms.PageRequestManager.getInstance()._onFormElementActive = function Sys$WebForms$PageRequestManager$_onFormElementActive(element, offsetX, offsetY) {
if (element.disabled) {
return;
}
this._activeElement = element;
this._postBackSettings = this._getPostBackSettings(element, element.name);
if (element.name) {
var tagName = element.tagName.toUpperCase();
if (tagName === 'INPUT') {
var type = element.type;
if (type === 'submit') {
this._additionalInput = encodeURIComponent(element.name) + '=' + encodeURIComponent(element.value);
}
else if (type === 'image') {
this._additionalInput = encodeURIComponent(element.name) + '.x=' + Math.floor(offsetX) + '&' + encodeURIComponent(element.name) + '.y=' + Math.floor(offsetY);
}
}
else if ((tagName === 'BUTTON') && (element.name.length !== 0) && (element.type === 'submit')) {
this._additionalInput = encodeURIComponent(element.name) + '=' + encodeURIComponent(element.value);
}
}
};
}
});
Run Code Online (Sandbox Code Playgroud)
这是一个JavaScript解决方法.它会覆盖现有方法,将x和y坐标放在地板上,然后使用这些新坐标调用现有方法.
Sys.WebForms.PageRequestManager.getInstance()._origOnFormActiveElement = Sys.WebForms.PageRequestManager.getInstance()._onFormElementActive;
Sys.WebForms.PageRequestManager.getInstance()._onFormElementActive = function(element, offsetX, offsetY){
if (element.tagName.toUpperCase() === 'INPUT' && element.type === 'image'){
offsetX = Math.floor(offsetX);
offsetY = Math.floor(offsetY);
}
this._origOnFormActiveElement(element, offsetX, offsetY);
};
Run Code Online (Sandbox Code Playgroud)