| You are here: | About>Computing & Technology>Delphi Programming> Learn Delphi for .NET> ASP.NET> Developing and Using Custom User Controls in Delphi ASP.NET applications |
![]() | Delphi Programming |
![]() Source CodeDeveloping and Using Custom User Controls in ASP.NETWhat are User Controls? Creating your First ASP.NET User Control in Delphi.Welcome to the 23rd chapter of the FREE online programming course:
Besides using HTML and Web server controls, you can easily create your own custom, reusable controls by using the same techniques you have learned to develop Web Forms pages. These controls are called user controls. Very similar to Win32 Delphi's TFrame objects, an ASP.NET User Control is a container for components; it can be nested within Web Forms or other User Controls. User controls offer you an easy way to split and reuse common user interface functionality across the pages of your ASP.NET Web application. Creating a Custom User ControlTo create a Web User Control, you start by adding a Web User Control component to a Web application. Next, you define the control's visual interface by adding other Web Controls and HTML elements to your user control. A user control can expose properties and can even introduce its own events.One of the simplest uses of a Web Server Control is to represent some "static" content that will appear on every Web Forms Page of your application, such as contact details or a common page footer / header. Let's see how to build a simple "Site Contact" User Control. I'll suppose you know how to create a new web application using your version of Delphi. Make sure you have at least one Web Forms Page (Default.aspx or similar). Adding a User Control to a ProjectHere are the steps to add a user control to your ASP.NET application.
An empty user control designer only displays the following "@Control" directive: <%@ Control Language="c#" AutoEventWireup="false" Codebehind="ContactInfo.pas" Inherits="ContactInfo.TContactInfo"%>User control declarative syntax is very similar to syntax used to create a Web Forms page; the primary difference is that user controls do not include the <html>, <body>, and <form> elements around the content. Adding Content to the ContactInfo User ControlWe'll keep our ContactInfo control rather simple. Either open up the "Design" view and drop a Table object on the designer; or open the "ascx/html" view and add the HTML table tag manually. The ContactInfo will host a copyright notice, and an "email" hyperlink. Two Label components will be used: "infoLabel" and "emailLabel". Also, a "static" hyperlink will be included on the User Control.<%@ Control Language="c#" AutoEventWireup="false" Codebehind="ContactInfo.pas" Inherits="ContactInfo.TContactInfo"%>As you can see, building/developing a user control is almost identical to working with the aspx web page. Let's now see how to add our user control to a web page ... Source Code |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | Print this Page | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |



