![]() |
Web Development »
ASP.NET Controls »
General
Intermediate
License: The Code Project Open License (CPOL)
Avoiding ActiveX Activation in IEBy Richard DeemingAn updated version of the AutoActivateControl class posted by Dundas Software. |
C#, Javascript, Windows, .NET 1.1, .NET 2.0, ASP.NET, VS.NET2003, VS2005, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
As a result of the Eolas patent, Microsoft has changed the way that Internet Explorer loads ActiveX controls. All interactive controls which are embedded directly within a page must now be activated before they can be used.

An article on MSDN[^] provides instructions on a workaround for this change. The work-around involves creating an external script file for every control instance, which may not be practical in a dynamic site.
Terrence Sheflin, of Dundas Software, recently posted an article[^] and a control which attempts to make the workaround more reusable. However, the control has several problems:
For example, if the control is applied to TargetControl, a page containing:
<form runat="server">
<h1>Page Heading</h1>
<div class="container">
<xyz:someControl id="TargetControl" runat="server" ... />
</div>
</form>
will actually be rendered as:
<form runat="server">
<script src="/embed.js"></script> <-- This line renders TargetControl
<h1>Page Heading</h1>
<div class="container">
</div>
</form>
The control does not expose a parameter-less constructor, so it cannot be used declaratively. Instead, the code in the Page_Load method must locate the target control and create an instance of the AutoActivateControl to wrap it. If the target control is within a templated parent such as a Repeater, this involves a call to FindControl for each instance of the template created.
OBJECT tags cannot be used unless that have the runat="server" attribute added.
HtmlTextWriter type for the current browser.
Internet Explorer doesn't actually need a unique external JavaScript file for every control instance. Instead, you can create a single external JavaScript file with a single method:
window.AutoActivateControl_WriteObjectElement =
function(elementData)
{
if ("string" != typeof(elementData) || 0 == elementData.length) return;
document.write(elementData);
};
You can then call this method from script within the page, and the control will be rendered without activation.
The original control uses the PreRender event to capture the output of the target control, and the RegisterClientScriptBlock method to include the output in the page. As a result, the control is rendered immediately after the opening <form runat="server"> tag, which is outside of the normal page flow.
The solution is to create a container control which will contain all of the controls to be modified. It can then use the RenderChildren method to capture the output and override the Render method to render the output in the correct location. With this solution, even static HTML can be targeted, so <OBJECT> tags no longer require the runat="server" attribute.
The new control is designed to be used declaratively, and can be used anywhere on the page. It will only affect browsers which support ActiveX controls (as detected by the HttpBrowserCapabilities class), and will render a <noscript> tag for situations when script is disabled.
<%@ Register
TagPrefix="tri"
Namespace="Trinet.Web.Utilities"
Assembly="Trinet.Web.Utilities.AutoActivateControl"
%>
<tri:autoActivateControl runat="server">
<xyz:someControl id="TargetControl" runat="server" ... />
<object classid="clsid: ... />
</tri:autoActivateControl>In .NET 2.0, the script will be loaded from an embedded resource, so it is not necessary to distribute the JavaScript file. If you want to override this behavior, you can set the UseScriptResource to false.
If you want to move the JavaScript file to a different location, you will need to set the ScriptLocation property to the new path:
<tri:autoActivateControl runat="server"
scriptLocation="~/scripts/AutoActivateControl.js">
As Mark Werner and FunkyMonkey have pointed out, it is also possible to avoid control activation by modifying the HTML DOM from an external script file [^] once the page has loaded. This method works with all pages, not just ASP.NET, and only requires a single line addition to each page.
TagPrefix attribute in the AssemblyInfo.cs file;
Assembly attribute of the <%@ Register ... directive;
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 15 Jun 2006 Editor: Smitha Vijayan |
Copyright 2006 by Richard Deeming Everything else Copyright © CodeProject, 1999-2009 Web21 | Advertise on the Code Project |