Thursday, August 1, 2013

A Imagebutton on a FormView / repeater isn't working in IE10 on Windows 8

If it's the same problem we ran across, the issue is that ImageButtons in IE10 submit the x and y coordinates of the click location as decimals, when ASP.NET 4.0 only understands integers.
The fix we did, which requires no server change or framework change, was to cheat a little bit, and replace all of our ImageButtons with a custom control which inherits from ImageButton and strips off the decimal parts.
Here's the class:
[DefaultProperty("Text")]
    [ToolboxData("<{0}:ImageButtonFixed runat=server></{0}:ImageButtonFixed>")]
    public class ImageButtonFixed : ImageButton
    {
        protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)
        {
            // Control coordinates are sent in decimal by IE10
            // Recreating the collection with corrected values
            NameValueCollection modifiedPostCollection = new NameValueCollection();
            for (int i = 0; i < postCollection.Count; i++)
            {
                string actualKey = postCollection.GetKey(i);
                string[] actualValueTab = postCollection.GetValues(i);

                if (actualKey != null)
                {
                    if (actualKey.EndsWith(".x") || actualKey.EndsWith(".y"))
                    {
                        string value = actualValueTab[0];
                        decimal dec;
                        Decimal.TryParse(value, out dec);
                        modifiedPostCollection.Add(actualKey, ((int)Math.Round(dec)).ToString());
                    }
                    else
                    {
                        foreach (string actualValue in actualValueTab)
                        {
                            modifiedPostCollection.Add(actualKey, actualValue);
                        }
                    }
                }
            }
            return base.LoadPostData(postDataKey, modifiedPostCollection);
        }
    }
And to use it, all you'd need to do is add this control to your page in place of ImageButton:

<%@ Register assembly="App_Code" namespace="XExcept.Controls" tagprefix="cc1" %>
<cc1:ImageButtonFixed runat="server" CommandName="Whatever" ImageUrl="whatever.png" />

Not a great permanent solution, but it works.

source : http://forums.asp.net/t/1905046.aspx/2/10?A+button+on+a+FormView+isn+t+working+in+IE10+on+Windows+8

No comments:

Post a Comment