tags:

views:

136

answers:

2

A lot of times, I find myself doing UI control manipulation in the code behind and wanted to find a clean way of doing this.

Use Case: A drop down has CSS1 style, editable in Edit mode but has CSS2 style, view only in View mode

I can achieve this by simply have a set of switch case statements. I can use polymorphism and create a EditMode and ViewMode class but that requires me to have a reference to the UI control to be passed to these classes. This tightly couples the UI and the logic layer which I want to avoid.

Any ideas?

EDIT: Can anyone give an example of externalizing the UI logic from the code behind?

A: 

Passing a control does not necessarily tightly couple, but I can understand the reasoning and would agree with it, as a general rule.

One option is to create the class as a UI class. This does not mean it has to be embedded in the ASP.NET web application, but rather that the library is set up as a web UI library. I do this by naming:

company.application.UI.{libraryName}

Your naming may be different.

In architecture, there is nothing wrong with having UI libraries that have polymorphic helper classes. I would not move these classes down to the business layer.

Gregory A Beamer
A: 

Take a look at Dynamic Data Web Application. There you can find one way to cleanly separate view controls from edit controls.

Thomas Eyde