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

后端 未结 10 1118
情深已故
情深已故 2020-12-08 07:48

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 doubl

10条回答
  •  长情又很酷
    2020-12-08 08:16

    I ended up sub-classing the ImageButton, and correcting the data before it was passed in for processing.

    using System;
    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.Security.Permissions;
    using System.Web;
    using System.Web.UI;
    
    namespace Xception.WebControls
    {
        [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal),
        AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal),
        DefaultEvent("Click"),
        ToolboxData("<{0}:ImageButton runat=\"server\"> ")]
        public class ImageButton : System.Web.UI.WebControls.ImageButton
        {
            protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)
            {
                NameValueCollection newCollection = new NameValueCollection();
    
                foreach (string key in postCollection.AllKeys)
                {
                    if (key.Equals(this.UniqueID + ".x", StringComparison.InvariantCultureIgnoreCase))
                        newCollection[this.UniqueID + ".x"] = Convert.ToInt32(Convert.ToSingle(postCollection[this.UniqueID + ".x"])).ToString();
                    else if (key.Equals(this.UniqueID + ".y", StringComparison.InvariantCultureIgnoreCase))
                        newCollection[this.UniqueID + ".y"] = Convert.ToInt32(Convert.ToSingle(postCollection[this.UniqueID + ".y"])).ToString();
                    else
                        newCollection[key] = postCollection[key];
                }
    
                return base.LoadPostData(postDataKey, newCollection);
            }
        }
    }
    

提交回复
热议问题