Wednesday, March 28, 2012

AjaxControlToolKit HTML Editor IE 9 Copy / Paste Bug

So, if you are reading this BLOG post, you probably already know that there is a bug in the AJAXControlToolKit's HTML Editor which while in IE 9, you cannot perform simple Copy/Paste operations.

This is a HUGE problem!  (Although, if you visit their website, the bug report only has a few votes.  This still boggles my mind!)

Well, as of the time this post was made, there still is no direct fix for this problem.  However, I have found a workaround.

Turns out, you can force a page to render in Compatibility mode for IE 7 or IE 8.  To do so, you need to insert the following META tag into the <HEAD> of your document.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />

You can also use EmulateIE7 to go to IE7 standards.



There's a gotcha here though!

Turns out, if that META tag isn't the very first tag to be found in the <HEAD> section, it doesn't work.

This isn't a problem for a lot of people, but for us, it was a big problem because we have some "black box" development tools which adds LINK files for styling info to the <HEAD> during page load.  It does this to the top of the tag!  DOH!

But wait!  The fix:

 Protected Sub Page_LoadComplete(sender As Object, e As System.EventArgs) Handles Me.LoadComplete
            Dim forceIE7Compat As New HtmlMeta
            forceIE7Compat.Content = "IE=EmulateIE8"
            forceIE7Compat.HttpEquiv = "X-UA-Compatible"
            Page.Header.Controls.AddAt(0, forceIE7Compat)
 End Sub

This code will execute after the page has finished loading and adds the META tag as the very first element to the HEAD of the page.

Hope this helps someone!

1 comment: