Search code examples
javascriptasp.netinternet-explorer-10

IE10 sending image button click coordinates with decimals (floating point values) causing a ParseInt32 FormatException


It seems like ASP.NET 4.0 is not prepared to handle ImageButton events triggered by Internet Explorer 10. The problem is that IE10 sends the image click coordinates as double values (with decimals), and ASP.NET tries to parse them as integers, presenting the following type of error:

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)

Googling around, some people suggest forcing IE10 to run in compatibility view. However, adding the meta tag <meta http-equiv="X-UA-Compatible" content="IE=10" /> does not solve anything; and adding <?xml version="1.0" encoding="UTF-8"> before <!DOCTYPE> doesn't work either.

Any solutions? Could I capture the click event with Javascript and remove the decimals somehow?

Note: Upgrading to Framework 4.5 and recompiling fixes the bug. No need to change the runtime version, since it's still 4.0.


Solution

  • Simply installing .NET Framework 4.5 can fix this problem.

    This can fix the problem even if you do not switch your application pool over to .NET Framework 4.5.

    In my case, I left the app pools at .NET Framework 3.5. Apparently installing .NET Framework 4.5 overwrites some files for other framework versions.

    Since it is so easy to install the new .NET Framework version, it's probably worth a try before bothering with the hotfixes (which did not work for me) or other solutions.

    See the workarounds section here