Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



LearnNow


XAMALOT
 


SSWUG

Reader rating:
Click here to read 7 comments about this article.
Article source: CoDe (2005 - Mar/Apr)


Article Pages:  1  2 3 4 - Next >


ASP.NET Development Through Web Controls and Declarative Programming

ASP.NET WebControls do more than just allow you to write reusable components. They can provide an entire approach to Web application development, allowing you to bring a new level of OOP to the UI and letting you program declaratively. Lately I've come to notice that no other programming term has more definitions than declarative programming. In this article, I will attempt to explain it in terms of how it applies to .NET development, specifically ASP.NET through the use of WebControls. I'll do this by illustrating some real-world examples that I have used in my own projects. In the end, I hope to leave you with an understanding of what declarative programming is, how you can use it when developing ASP.NET Web applications, and how, with the help of WebControls, to use it as an approach to ASP.NET development.

This article assumes knowledge of ASP.NET and the use of the WebControls Microsoft provides. Some knowledge of custom WebControls, at least in concept, is helpful. But most importantly you should have an open mind for looking at what is most likely a different way of programming sites in ASP.NET.

"
The Calendar control is another great example of Web Control-based declarative programming in ASP.NET. Next time you pop one onto a WebForm, view the resulting source and you'll see the amount of HTML the code behind the control has drawn for you. All you've had to do is declare some of its properties.
"

OK, time to pick a fight. What is declarative programming? Well, as I stated above, I've seen many definitions of that term lately; but most of them pretty much break down into similar descriptions. It is a style of programming whereas at one level you define, in detail, how a variety of things are done, and from another level you instruct as to what needs to be done. Let me explain with a couple of examples in the context of languages I'm sure you already know.

Back to the Basics

Think about how you create a simple table in HTML: the first thing you do is define your table tags using <TABLE> and </TABLE>. A table consists of rows and columns, so of course you use <TR> and </TR> to declare each row, and then one or more <TD> and </TD> tags to define each column in each row. This is a table at its simplest form:

<TABLE>
   <TR>
      <TD>This is cell 1 in row 1</TD>
   <TD>This is cell 2 in row 1</TD>
   </TR>
   <TR>
      <TD>This is cell 1 in row 2</TD>
   <TD>This is cell 2 in row 2</TD>
   </TR>
</TABLE>

I know, you know this already, but indulge me because I promise I will build on this idea. This simple code tells the rendering engine in the browser to draw a table on the page. Obviously there is some machine code at the browser level to actually draw the physical table on the page and display it properly. Now, what do you do to alter the way this table looks? Say, for example, you want thicker borders, or some extra padding and everything in the first column to be right justified. This is where the border, cellpadding, and align attributes come in. By simply adding them to your HTML tags, you've totally altered the way the table looks. You didn't need real code because you just alter attributes, or properties if you will. The rendering engine that interprets the HTML knows how to alter the appearance of the table based on what you asked for. Remember the what to do and how to do it separation I mentioned earlier?

OK, let's turn the clock back all the way to the release of ASP.NET in February of 2002 (betas not counting). Microsoft introduced the Web Control which let developers do things in what appears to be HTML-like syntax. Starting with a simple Web Control, here is how to declare a textbox :

<asp:textbox id="txtMyTextbox"></asp:textbox>

I'm leaving out the properties here for brevity, but I think you know where I'm going with this. Since browsers can still only understand HTML, the ASP.NET parser takes this textbox declaration and turns it into the appropriate HTML; and based on various properties you can change, the browser renders the HTML slightly different. The ever-popular DataGrid control, though more complex, works the same way. It gives developers the appearance of an actual grid with all sorts of customizable features; much akin to its WinForm cousins. But as I said, the browser can still only understand HTML, so ASP.NET once again converts a simple looking declaration, <asp:datagrid> </asp:datagrid>, into what turns out to be a regular HTML table. All the properties you can set on the DataGrid, and all the programming you can provide to customize it and to fill it with data, will still only result in an HTML table, albeit a pretty complex one in the end.

This is declarative programming in ASP.NET at its simplest. I say simplest, because you, as the ASP.NET developer, have not really had to do much to get the grid (or the textbox) to display, other than drag it on a WebForm, or code the <asp:...> tags. All the code that actually draws the resulting HTML has been done for you by the folks at Microsoft?it has been programmed declaratively. In the world of Web Controls using ASP.NET, declarative programming moves some of the code off of the WebForm and into the Web Controls. Let's go back to the definition I gave before and apply it here: the Web Controls have determined how all sorts of things are to be done (rendered in this case), and the WebForm has determined what needs to be done.

If all of this sounds familiar to you, it should. This is the very basis of object-oriented programming. You design a class and expose properties, methods, and events, and it is a form of declarative programming. When you gave your objects all that cool functionality and things it can do by putting a lot of programming into them, you've relieved just that much work from any developer (yourself included) that uses your classes. Now you're seeing a classic design paradigm at work in the UI level. Heck, this has been familiar in the UI since Visual Basic 1.0 when you first dropped that textbox (remember the VBX?) on to your first form.

&

By: Miguel Castro

Miguel is an architect with IDesign who specializes in architecture consulting and building .NET solutions. He is a Microsoft MVP and INETA speaker and has been a software developer for over 22 years. With a Microsoft background that goes all the way back to VB 1.0 (and QuickBasic in fact), Miguel jumped on .NET as soon as the first public Beta was released and has provided .NET solutions for clients around the country in a variety of industries. He considers himself to be a .NET Developer and Architect and has equal love for both VB and C#, and no tolerance for language bigotry. He’s spoken at numerous user groups around the country as well as developer conferences.

He’s the author of the CodeBreeze code-generator, which among things can be found on his Web site:

www.steelbluesolutions.com

Miguel currently lives in Lincoln Park, NJ with his wife Elena and his daughter Victoria.

subscriptions@infotekcg.com

Fast Facts

Declarative programming by way of custom controls has always been a part of Windows (WinForm) development. But it wasn't until the release of ASP.NET that developers got a chance to apply these principles and techniques to Web development.



Article Pages:  1  2 3 4 - Next Page: 'Are Grids All You Got?' >>

Page 1: ASP.NET Development Through Web Controls and Declarative Programming
Page 2: Are Grids All You Got?
Page 3: Web Site by way of WebControls
Page 4: Web Site by way of WebControls (con't)

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3 out of 5

38 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      LearnNow

 

SSWUG