Inconvenient Control Adapters

Control Adapters are a great way to modify the presentation layer of any control out there: no matter whether it’s sealed or internal. And while they are pretty easy to setup you can find yourself spending a couple of hours if somehow they seem not to be applied…

To modify the presentation of an existing control you need two things: a Control Adapter class which comes in a couple of tastes (check out the System.Web.UI.Adapters and System.Web.UI.WebControls.Adapters namespaces for more details) among which the one I use the most: ControlAdapter, MenuAdapter and PageAdapter. Depending what kind of control you want to customize you will have to create a new class inheriting from one of these base classes.

The second thing is a declarative markup to bind your Control Adapter to an existing control. It’s supposed to be defined using the Browser Definition File Schema and should be deployed either into a new or existing .browser file in App_Browsers in the IIS directory of your Web Application.

So imagine you have setup things correctly and even have seen your Control Adapter worked for a while and then all of a sudden things don’t seem to work anymore: neither CTRL+F5 or an IIS reset seem to help. Did you just broke your environment, the solution or what is just going on?

Luckily the solution is really easy yet one of the things you have to know. To improve the overall performance ASP.NET caches some of the output. I have to admit that I don’t know all of the plumbing but I assume that ASP.NET stores information whether there any Control Adapters for particular controls and whether they should be applied (you can explicitly disable applying a Control Adapter to a control by using the AdapterEnable=”false” attribute on the Control). So if the information about the Control Adapters is being cached it might’ve just happened that the changes you have done are not being reflected and you need to delete all of the ASP.NET Temporary Files. To do that:

  1. Stop IIS (either using the UI or command line iisreset /stop)
  2. Navigate to %windir%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
  3. Delete all the files in this folder
  4. Start IIS (either using the UI or command line iisreset /start)

In most of the cases the above does the job and makes ASP.NET rebuild the controls. Knowing these few steps might just save you a couple of hours.

Technorati Tags: ASP.NET


comments powered by Disqus