Coming from PHP and more specifically many of the MVC frameworks out their, I’ve been use to using basic foreach and if constructs in PHP directly in the layout. Now that I’m learning ASP.NET I’m presented with more proprietary concepts like a ListView to control looping, etc…
So to give an example of what I want to do..
<div id="container">
<h1 class="header">Title</h1>
<% For Each item In ItemsCollection %>
<% If item.Name IsNot Nothing %>
<h3>This is the layout for <%= item.Name %></h3>
<% End If %>
<p><%= item.Content %></p>
<% Next %>
</div>
Then there isn’t a lot I have to handle in the Code Behind file… besides making ItemsCollection available.
Is This considered Bad Practice? Should I spend the time learning the proprietary controls for ASP.NET? Are there specific limitations of this approach?
This may be subjective, but there are tons of documentation about why the standard controls such as the ListView were created. The primary benefits is separation of concerns, and avoidance of “spaghetti code”, which is exactly what your sample is.
I believe that if you’re going to be developing in .NET is is well worth your time to learn the controls, and the background for these controls. A lot of the power, productivity, code clarity, and ease of .NET development is hinged around such design principles. Whether they are “Correct” or “right” compared to other environments is debatable.
All of the above beside…
The short version is that if you’re going to be developing in .NET using the WebForms model, you should code like a .NET WebForms developer, if for no other reason than that it’s likely that a .NET WebForms developer will need to maintain your code some day. We’ve all been trained to expect certain things, and stuff like this drives us nuts when maintaining other people’s code.
Edit
Of course, if you go with ASP.NET MVC, you’ll be in your comfort zone and my opinion will not apply.