Home arrow ASP.NET arrow Page 5 - Reduce Repetitive Code with ASP.NET Custom Controls

Reduce Repetitive Code with ASP.NET Custom Controls

In this article Rich explores the world of ASP.NET Custom Controls and how they can dramatically simplify development of ASP.NET web applications.

Author Info:
By: Rich Sbarro
Rating: 5 stars5 stars5 stars5 stars5 stars / 57
January 08, 2003
  1. · Reduce Repetitive Code with ASP.NET Custom Controls
  2. · Creating the Control
  3. · Databinding to the Control
  4. · Handling ViewState and Post Back Events
  5. · Implementing in an ASP.NET page
  6. · Conclusion

print this article

Reduce Repetitive Code with ASP.NET Custom Controls - Implementing in an ASP.NET page
(Page 5 of 6 )

Implementing your custom control in an ASP.NET page is a fairly simple matter. In fact, the code below shows how to do just that.

<%@ Page language="c#" Codebehind="ContactsDropDown.aspx.cs" AutoEventWireup="false" Inherits="WebControls.ContactsDropDown" %>
<%@ Register TagPrefix="Web" Namespace="WebControls" Assembly="WebControls" %>
<title>Reduce Repetitive Code with Custom Controls</title>
font-family: Tahoma, 'Times New Roman';
font-size: 12px;
<form id="ContactsDropDown" method="post" runat="server">
<span class="text-default">
<h2>Contact Information</h2>
<asp:Literal ID="litContact" EnableViewState="False" Runat="server" />

The two lines that do all the work are basically the <%@ Register %>tag that references the assembly that contains the control, and the <Web:ContactsDropDownList /> tag that tells ASP.NET to render the control you just created (remember that the prefix defined in the Register tag must match the prefix used to declare your control!).

And of course, since the ContactsDropDownList handles its own databinding, there is no need to worry about obtaining the Contacts data in the code behind page.
blog comments powered by Disqus

- How Caching Means More Ca-ching, Part 2
- How Caching Means More Ca-ching, Part 1
- Reading a Delimited File Using ASP.Net and V...
- What is .Net and Where is ASP.NET?
- An Object Driven Interface with .Net
- Create Your Own Guestbook In ASP.NET
- HTTP File Download Without User Interaction ...
- Dynamically Using Methods in ASP.NET
- Changing the Page Size Interactively in a Da...
- XML Serialization in ASP.NET
- Using Objects in ASP.NET: Part 1/2
- IE Web Controls in VB.NET
- Class Frameworks in VB .NET
- Cryptographic Objects in C#: Part 1
- Sample Chapter: Pure ASP.Net

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials