Calendar

<<  mars 2010  >>
lumamejevesadi
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

(mai 10, 2008 13:32)

I have given here some clues about creating control adapters. A few days after I have started to use them, I have encountered some very special problems. In fact the adapters have the following hierarchy :  the .NET framework expose a ControlAdapter from which derives a WebControlAdapter and a PageAdapter. THe name of these classes being explicit enough to let you know in which cases you should use which one.

As a consequence, when you want to adapt a WebControl, you should use a WebControlAdapter or one of its derived classes. So far, so good, so simple.

But what you should know is that the framework expose in the WebControl class a method called Render. Never seen it or overriden it ? Normal it's a protected internal one. This method is responsible of the rendering of the control and so does : RenderBeginTag, RenderContent and RenderEndTag. And these are the three methods you will normally work with.

And so what does the WebControlAdapter : it will redefine the Render method to do the same work : RenderBeginTag, RenderContent and RenderEndTag. And each of these methods will either call the apdater's equivalent method, or the one of the control itself.

Pretty normal. No problem there.

Well... Almost... Let's imagine just one moment, that someone has defined some other code in the Render method ? Well... That would bring some troubles no ? Right it would break the .NET standard but let's imagine. Of course, in that case, using a WebControlAdapter would just bring a you a no-longer working control.

It's in fact what happens in the BaseValidator class (which inherits from WebControl of course). The Render method does a lot more, like rendering javascript, the "display" and "visibility" attribute.

Which conclusion, what can we say now ? Never use a WebControlAdapter when working with a BaseValidator (or any derived class). Prefer working with a ControlAdapter instead !

Billets liés

Commentaires

janvier 19. 2009 08:09

what the great info.about the Web ControlAdapters and BaseValidator
this blog was so wonderful

Busby SEO Test

Ajouter un commentaire


 

  Country flag





Live preview

mars 12. 2010 03:44

Powered by BlogEngine.NET 1.2.0.0 | Theme by Pierre-Emmanuel Dautreppe