Overview

Suppose that you have found the perfect control that works with almost all the browsers you need to support, but suppose it has breaking functionality for a particular browser.  How can you solve this problem?

One Solution

Sometimes the easiest solution may be a browser specific adapter.  The adapter can remove the original control and replace it with one that is only targeted at a single browser (or a subset).  Then, when the preferred control is fixed, it can be used directly without changing the application code.

This solution has at least two components:

  1. A change to a browser file in the App_Browsers folder
  2. A control adapter that implements the required functionality.  Optionally using an alternative control.
  3. (Optional) an alternative control

Changing the App_Browsers file

In the appropriate browser file, add an adapter entry:

<controlAdapters>
    <adapter controltype="YourNamespace.YourOriginalControl"
             adaptertype="YourNamespace.YourControlAdapter" />
</controlAdapters>

 The Control Adapter

The Control Adapter is provided by a class derived from System.Web.UI.Adapters.ControlAdapter.  The adapter can provide event handlers for standard events, but typically the OnLoad and Render methods are overidden.

The OnLoad method calls base.OnLoad and might register some client script using the Page.ClientScript.RegisterClientScriptBlock method.  It might also enable, disable, add or remove other controls on the page.  The OnLoad method may also change the properties of the original control, perhaps adding additional client-side events.

The Render method calls base.Render to render the original control's content.  However, it might wrap this in other HTML output that the client script uses to control display or handle additional events.

You use the this.Control property to access the adapted control.

Comments

At the time of writing, the ASP.NET AJAX toolkit's HoverMenuExtender control doesn't work perfectly in Internet Explorer 6.  This method was used to remove the HoverMenuExtender from IE6 output and to replace it with custom HTML, JavaScript and event handling.  The adapter was applied to the display control, not to the HoverMenuExtender itself.

Versions

  • Microsoft .NET Framework 3.0
  • ASP.NET AJAX Toolkit 1.0.10920.23306

Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist
posted @ Thursday, January 03, 2008 4:21 PM | in ASP.NET .NET Software Development

Comments

No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  


Please add 8 and 1 and type the answer here: