Click here to Skip to main content
11,715,160 members (75,712 online)
Click here to Skip to main content

IE10 and ImageButtons

, 20 Nov 2012 CPOL 16.8K 4
Rate this:
Please Sign up or sign in to vote.
A fix for ImageButtons problem in IE10 when project is not 4.5

Introduction

Let's discover how Microsoft introduces a new concept: pixel splitting...

Background

For some reason, your ASP.NET 4.0 solution cannot be updated to 4.5 (that's my case). Using a lot of ImageButtons, the application now crashes in IE10 (Win8 but also Win7 preview).

After searching around, I found that the problem is caused by IE10 itself. When a user clicks on an imageButton, a NameValueCollection is created with a few key/values. Among these, we can find the coordinates of the clicked control.

But, for obscure reasons, IE10 sends this information in decimal (position of the control can be x: 18.66648424 y: 54.687142514 (???)).

ASP.NET is waiting for an integer value and logically fails when attempting to convert the string "18.66648424" into an integer.

Using the Code

I found a little fix for this by overriding "PostLoadData" method in ImageButton. So, all you need to do is to override this method with something like this:

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);
                if (actualKey != null)
                {
                    string[] actualValueTab = postCollection.GetValues(i);
                    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);
        }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Arno1973
France France
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionToolTip should not be disappear after removing mouse pointer from that object. Pin
argeraju16-Feb-14 23:16
groupargeraju16-Feb-14 23:16 
QuestionImageButtons do not work in IE10 (i m using .net framework 2.0 ) Pin
argeraju9-Dec-13 18:17
groupargeraju9-Dec-13 18:17 
QuestionImageButtons do not work in IE10 (i m using .net framework 2.0 ) Pin
argeraju9-Dec-13 18:15
groupargeraju9-Dec-13 18:15 
QuestionWhere does the code go? Pin
Richard Creer17-Jun-13 4:29
memberRichard Creer17-Jun-13 4:29 
AnswerRe: Where does the code go? Pin
Arno197317-Jun-13 5:41
memberArno197317-Jun-13 5:41 
QuestionThanks! Pin
Ashley van Gerven5-May-13 18:04
memberAshley van Gerven5-May-13 18:04 
Questioni have used this code in ASP.NET, VB.NET Pin
Elayaraja Ponnusamy14-Apr-13 20:11
memberElayaraja Ponnusamy14-Apr-13 20:11 
Questioncan't override LoadPostData Pin
Member 99673175-Apr-13 3:04
memberMember 99673175-Apr-13 3:04 
I tried to implement this solution, but found that in our site (.NET 4 framework), the LoadPostData method is not available for the imageButton control.
Am I missing something?

SpencerK
QuestionOverflowException Pin
MarjaR15-Mar-13 4:01
memberMarjaR15-Mar-13 4:01 
AnswerRe: OverflowException Pin
MarjaR16-Mar-13 3:03
memberMarjaR16-Mar-13 3:03 
QuestionPossible IE bug Pin
Abdias Software21-Nov-12 16:31
memberAbdias Software21-Nov-12 16:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150901.1 | Last Updated 20 Nov 2012
Article Copyright 2012 by Arno1973
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid