系統Log顯示,某個運作多年的網站最近冒出以下錯誤:

System.Web.HttpUnhandledException: 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.WebControls.ImageButton.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection)

程式久未更動,忽然出錯令人狐疑,後來找出關鍵點,當使用IE10瀏覽時才發生問題!

爬文佐以實驗,整理出以下心得:

  1. 發生條件: 1) 使用UpdatePanel包住ImageButton的ASP.NET網頁,2) IE10使用標準模式檢視(切成相容模式可避開)
  2. 遇到相同狀況的開發者不少,該問題在MS Connect已累計超過50票
  3. 問題根源為AJAX Client Library在IE10標準模式以UpdatePanel執行ImageButton送出,X、Y座標參數出現小數點,但ASP.NET PostBack接收時只接受整數
  4. ASP.NET 3.5/4.0都有此問題,ASP.NET 4.5則已修正

理論上只需調整AJAX Client Library或ASP.NET解讀X/Y值的邏輯即可解決,而目前已有Hotfix:

  • 2783780 Hotfix rollup 2783780 is available for the .NET Framework 2.0 SP2 in Windows Server 2003 SP2 and Windows XP SP3
  • 2784147 Hotfix rollup 2784147 is available for the .NET Framework 2.0 SP2 in Windows 7 and Windows Server 2008 R2
  • 2783767 Hotfix rollup 2783767 is available for the .NET Framework 4

安裝後一帖見效,問題排除。


Comments

# by 阿信

我是用這個解決的 https://connect.microsoft.com/VisualStudio/feedback/details/755419/asp-net-4-0-and-ie10-click-on-imagebutton-in-updatepanel-produces-error-click-on-normal-button-does-not 裡 由 Microsoft 在 2013/6/16 於 下午 09:50 公佈 Thanks for your feedback. Recently we released several GDRs for IE related bugs. You may want to have a try on these patches. .Net 4.0 http://support.microsoft.com/kb/2836939 .Net 2.0 http://support.microsoft.com/kb/2836943 http://support.microsoft.com/kb/2836942

# by Jeffrey

to 阿信,謝謝回饋。

Post a comment


45 + 22 =