Non-visual Controls are not just Components

Thoughts on non-visual controls in ASP.NET Whidbey such as SqlDataSource, and the new NonVisualControl metadata attribute.
Stephen Walther writes on TheServerSide.net:

Since it is part of the essential nature of a control to have a visual representation, the SqlDataSource is ill-conceived. Really, the SqlDataSource control should have been implemented as a component and not as a control.
I disagree, and given this design was something I was responsible for, I thought I should go ahead and share my own opinion. A little history first: This approach was actually first taken back in the Web Matrix days (when the VS model was based on DataSet components). We didn't have code-behind support and so, when we first introduced DataSource objects, the only choice we had was to implement them as controls. As we got the model working, we saw some rather compelling benefits to the declarative model, and so it seemed fit to continue building on it.

But more than just working around a limitation, fundamentally, I see controls like SqlDataSource as more than just mere components. They are controls in the sense that they participate in the page lifecycle, even though they don't offer a visual rendering. For example, data source controls manage view state, listen to OnInit, and LoadComplete events on the page to detect changes in parameter values etc.

The same is true of other non-visual controls. For example, the WebPartManager does something interesting in a whole bunch of control and page lifecycle events, and does in fact render script into the generated markup. Furthermore, it is in fact the parent control for all the WebParts on the page regardless of which zone they appear in!

Sure, one could invent a mechanism to allow components participate in the page lifecycle (which I personally think we should do... v-next perhaps). What I will agree to is that the design-time support for non-visual controls is somewhat lacking. All you can do today is toggle the visibility of non-visual controls. The complete idea behind non-visual controls was that dragging/dropping from the toolbox one would add it to the head of the page and not the body, and that any control in the head would automatically show up in the component tray, but that vision was not fully realized this time around.

Daniel Cazzulino has strongly argued for the component tray to be re-instated for some time now. I fully agree with him there; not necessarily for the sake of dropping arbitrary components, but for displaying non-visual controls. For arbitrary components, I think we should have a declarative syntax for them, and they should be persisted into the head, not in code (another v-next thought... in the same post).

While we're on the subject, check out the new System.Web.UI.NonVisualControlAttribute. Both the toggling behavior and intellisense listing tags for non-visual controls in the head section is based on that piece of metadata. Hopefully, it will be used to do more in the future, so start using it now, where it makes sense.
Posted on Monday, 12/6/2004 @ 7:27 PM | #ASP.NET


Comments

11 comments have been posted.

Derek Simon

Posted on 12/6/2004 @ 11:25 PM
The problem with these "non-visual controls" is that they break the n-tiered model that we're all familiar with. I don't blame Stephen Walther for disliking the idea-- I can't understand it myself.

Comparing the WebPartManager control to the SqlDataSource control doesn't make much sense either. The WebPartManager is, by simple logic, a part of the presentation of the page. The SqlDataSource control is not.

Nikhil Kothari

Posted on 12/7/2004 @ 9:33 AM
The n-tier model is an orthogonal issue, which affects the choice of data source control you use. If the separation between presentation and data access is important, as it should be for real apps, then by all means, the app should not be using SqlDataSource.

For the purposes of this post which is about the design choice of whether non-visual controls like data sources are better suited as controls or components, I would make the same claim about ObjectDataSource, or any other data source control for that matter. They are all controls, and do control-like things, and hence are more than just components.

Bertrand

Posted on 12/7/2004 @ 2:58 PM
There we go again. Data Source controls are not a data layer in themselves and don't "break" the n-tiered model any more than the code you write in your UI layer to communicate with other layers. The ObjectDataSource or any specialized data source control that you may write is just a declarative way for the UI to communicate with other layers. The only difference between the boilerplate communication code you had to write before and the data sources is that now it can be declarative.
More on this here: http://weblogs.asp.net/bleroy/archive/2004/07/12/180921.aspx

dru

Posted on 12/9/2004 @ 2:45 PM
I really like the idea of the tray for non-visual controls. I hate seeing the ugly non-visual controls in my layouts. So three cheers for a better programming model, and three cheers for a future that includeds the tray!

I like the concept of System.Web.UI.NonVisualControlAttribute, would make it easy to get all of these controls into the tray I would think.

Is the CAPTCHA case sensitive?

Nikhil Kothari

Posted on 12/9/2004 @ 10:50 PM
Yes, the CAPTCHA is case-sensitive.

Do you think it would be much more usable if it weren't? I guess so... will make this change in the next update to my site.

Kevin Dente

Posted on 12/13/2004 @ 8:41 PM
+1 for displaying non-visual controls in the componet tray (I had an exchange with Bertrand on his blog on this same topic). Displaying that stuff on the page really doesn't make for an ideal design experience (for example, the way page reflows when you show or hide non-visible controls). Bertrand argued that rendering data source controls on the page lets you do stuff like putting data sources in a datalist, but I think that's really a corner case. I really like the idea that non-visual controls placed in the head show up in the tray - that allows you to support Bertrand's example, while leaving the more typical case with a better user experience. Should I submit a ladybug request now? :)

Nikhil Kothari

Posted on 12/14/2004 @ 2:23 AM
Kevin, sure go ahead and post the bug...
Then I'll have your bug as backing when I try to get some extra priority points for this sort of thing in the tool :-)

shanthu

Posted on 1/12/2005 @ 10:54 PM
These non-visual controls have been a boon for me. I was tasked( by myself ) to comewith a huge prototype with lot of functionalities in a very short period.

But, from the architectural point of view, I think that, this idea is flawed. We will see people mixing the presentation and data access layer. In an ideal world, these two should be as far as possible ( some glue in between).

If these were components instead of controls, it would have helped a great to debug and see what is happening underneath.

Nikhil Kothari

Posted on 1/14/2005 @ 1:32 AM
I am not sure I agree debugging components is any easier than debugging controls... I think the debugger does a pretty nice job debugging either...

Having declarative means of specifying logic does not automatically lead to mixing presentation and data access code. I could create a business object encapsulating SQL statements, and use ObjectDataSource to make it accessible to the presentation layer. Or I could go a step further, create stored procedures, encapsulate sproc calls in a business object, and use ObjectDataSource to make the object usable declaratively from the UI layer. Or if I am testing something quick, and the focus is on experimentation, I might opt to ignore the separation, and go about it using SqlDataSource and embed sql statements directly in the markup. It all depends on the requirements, the cost and the resulting value/ROI.

ASP.NET as a platform needs to support the spectrum of development needs and styles, as well as create a mechanism for 3rd parties to build similar components that support the model of declarative specification of application logic and behavior. So I guess, I don't see the architecture as flawed... though I guess its no surprise I'd say that about something I've worked on for some time :-)

AndrewSeven

Posted on 1/18/2005 @ 5:23 PM
I voted on that bug.

I really don't care about having the exact component tray functionality (code-ass err code-behind), but I strongly believe that controls that do not render visual content should be presented differently at design time.

Remember the Timer and other VB6 controls that you just stick in some empty space where you have room?
Where do I put these non visual controls? I just opened up up Web Express 2005, I put an SqlDataSource, a DataList, entered template editing mode and then dragged the SqlDataSource grey-block into the template.
LOL

Gopi Chand

Posted on 3/18/2005 @ 10:56 AM
CONTROL/COMPONENT

A control IS-A component in the general scheme of building event-driven applications, where we "drag and drop the components, set the properties, and define the event handlers." It'll be nice if this scheme is preserved and is indistinguishable for both windows-forms and web-forms applications.

DECLARATIVE/PROCEDURAL

The declarative model is a natural fit in an event-driven application because it's the time-sequence of events that determines the application behavior and not the sequence in which the components are dropped and wired into the application. [Any requirement that a parent has to be created before a child, while sounds natural, is arbitrary.]

VISUAL/NON-VISUAL

Non-visual components should have visual representation during design so that we can wire them up the same way as the visual components. Having a separate tray for non-visual components makes sense so they don't come in the way of the visual-component layout.

CONCLUSION

Whidbey has to come up with a better explanation for deviating from the above well-thoughtout and proven paradigm.
The discussion on this post has been closed. Please use my contact form to provide comments.