Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Architecture
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
Bing
BizTalk
Book Excerpts
Build and Deploy
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Design Patterns
Development Process
Display Technologies
Distributed Computing
DotNetNuke
DSL
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
Internet Explorer 8.0
Interviews
iPhone
Iron Ruby
Java
Java Script
jQuery
LINQ
Linux
Mac OS X
MDX
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
Network
NHibernate
Object Oriented Development
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
Podcasts
Post Mortem
PowerPoint
Print/Output
Product News
Product Reviews
Project Management
Python
Q&A
Rails
Rake
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Search
Security
Services
SharePoint
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 CE/AnyWhere/Mobile/Compact
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
Tips
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 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WF
Whitepapers
Windows 7
Windows Azure
Windows Live
Windows Server
Windows Vista
WinForms
Workflow
WPF
XAML
XML
XNA
XSLT



DevConnections


 


CODE TRAINING

Reader rating:
Click here to read 6 comments about this article.
Article source: CoDe (2006 - Sep/Oct)


Article Pages:  1  2 3 4 5 6 - Next >


Web Control Enhancements in ASP.NET 2.0

I’m sure by now you’ve read more than your share of books and articles describing new ASP.NET 2.0 features. Master pages, themes, providers, etc., are all great, but have you read anything regarding custom Web control development and what has changed in 2.0? Well that’s what I’m here to tell you. If you’ve become involved in control development, either through my articles or on your own, I’ll describe some very cool enhancements that you can put to work right away in your controls using ASP.NET 2.0.

This article assumes a basic knowledge of custom Web control development as explained in my two-part article series, “Custom Web Controls Demystified” published in the Sept/Oct 2005 and Nov/Dec 2005 issues of CoDe Magazine. In this article, I’ll enhance the EmailContact control that I built in the second part of that article.

"
If you constantly forget to implement INamingContainer in your composite controls, the new CompositeControl class will be a welcome addition.
"

Ok, so before you misinterpret the title of this article or make any false assumptions about code compatibility, let me start by telling you that all of the Web controls you developed in ASP.NET 1.1 (or 1.0) will work just fine in 2.0. Feel better? Good. Microsoft has not changed anything that will break your existing code. Everything that I will teach you here involves new and exciting technologies that you can add to existing controls or use with new ones.

New Enhancements

Table 1 describes several of the most important enhancements for custom Web control development. These are the ones I will cover in this article, but if you choose to research this topic further, you’ll find that there are several other changes and enhancements in the Web control arena, including Control Adapters, several base classes, region editing, and others. Perhaps I will make some of them the topics of future articles.

Enhancing an Old Friend

In my two-part article series called “Custom Web Controls Demystified” I developed a custom Web control named EmailContact (Figure 1) and allowed you to provide your sites with a “contact us” form, complete with e-mailing functionality. In this article, I’ll enhance that control with the functionality I’ve summarized above.

Click for a larger version of this image.

Figure 1: The EmailContact control in its default state.

If you have not read the previous articles, I strongly recommend that you do so in order to familiarize yourself with this control. If you’re a seasoned Web control developer, you should have no trouble following along.

A New Base Class

For a while now, developers have used the WebControl class to derive their visual Web controls. I say “visual” because controls that do not render anything to the browser are typically derived from the Control class. This has not changed and you should continue to use the Control class for any controls that perform invisible functionality or render anything else other than visual HTML to the browser. You should also continue using the WebControl class for any controls you develop using the rendering technique. However, most of us develop composite controls in order to leverage the power of existing controls. In this case, you’ve always inherited from the WebControl class, but you’ve also been forced to remember a few other details and if you forget them, that has always caused a lot of grief.

Composite controls must implement the INamingContainer interface and simply needs to be included by your control class, and forgetting to do so causes all sorts of problems. This interface ensures unique tag naming in all the HTML tags that your control and any controls in its control hierarchy may render. This is crucial in case you have more than one composite control of the same type on a single page. In such a case, you need to ensure that any child elements render with unique names.

Prior to ASP.NET 2.0, composite control developers also needed to remember to call EnsureChildControls in the Render method of a control. If you read back in the previous articles, I showed you how to override the Render method and make this call just before calling the Render method of the base class. This step is necessary in order for the control to render correctly in the design surface of Visual Studio. Forgetting this detail caused some inconvenience.

These two steps were so common in composite controls that many developers had a base class that included these two details and developers derived all of their new composite controls from this base class. ASP.NET 2.0 offers the [appropriately named] CompositeControl. Use this class to build your composite controls and you’ll never again have to remember to implement INamingContainer or perform an EnsureChildControls call from the Render method.

There are a couple of other new base classes that deal with data bound controls and so forth, but I’ll make them the topic of a future article on data binding custom controls. (Are you salivating yet?)

&

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

ASP.NET 2.0 does not break any existing controls from 1.1, but it adds a whole bunch of new ones, as well as a several new technologies for control development.



Table 1: ASP.NET 2.0 Web control enhancements.
EnhancementDescription
New Base ClassesASP.NET 2.0 introduces a few new base classes from which to derive your controls. I’m going to brief you on the most important one, CompositeControl, and how it can save you grief that you’ve all dealt with in the past.
ControlStateA cousin to the familiar ViewState, ControlState eliminates the all-or-nothing approach to state management and allows you to avoid pitfalls in the case that the control user turns off state management in a site (or page).
Smart TagsWindows control developers rejoice! This enhancement is good for you too! You know that popup window that opens up on the design surface when you click on that new doohickey in the upper right-hand corner of a control? I’m going to show you how to create one for your own controls.
Template Design-time EditingAdding design-time editing capability to control templates in 1.1 was an immense hassle. Luckily, ASP.NET 2.0 makes adding this functionality incredibly easy. I included this topic in last issue’s, “Web Control Templates Explained,” but I will cover the editing-specific details again.
Auto FormatThis enhancement is awesome! You’ve seen how you can choose from a list of predetermined formats on the good ol’ DataGrid control. ASP.NET 2.0 makes giving your own controls this ability easy; it’s almost a shame not to do it for all of your controls.
Web ResourcesThis is one of my favorite enhancements since I’m always developing controls that rely on images here and there. In ASP.NET 2.0 you can now deploy a control’s DLL and nothing else. That’s right-you can now embed images and other resources into the control’s DLL file. Think of this as a poor man’s linker.


Article Pages:  1  2 3 4 5 6 - Next Page: 'ControlState' >>

Page 1: Web Control Enhancements in ASP.NET 2.0
Page 2: ControlState
Page 3: Smart Tags
Page 4: Control Designers
Page 5: Auto Format
Page 6: Web Resources

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:
4.2 out of 5

36 people have rated this article.

      DevConnections

 

DevReach