Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Extending Built-In Web Controls - ASP.NET

RSS
Modified on Fri, Jul 24, 2009, 9:35 AM by Administrator Categorized as ASP·NET Web Forms
{outline|||Step <1> - }

Overview

Although you can create a server control within its own project, sometimes you just want to extend a built-in ASP.NET web control for a single website. Here's how.

Walkthrough

Create Extender Class

  • Create yourself a new class in the App_Code folder of your website, naming the class whatever you like.
  • Have the class inherit from whatever control you like in the System.Web.UI.WebControls namespace.
  • Be sure to specify a namespace for your class — you'll need it for the web.config file.
  • Add whatever methods and properties you require.

Configure Your Website

  • In the Web.Config file, add the following entry. This allows you to bypass the adding of the <%@ Register %> tag at the top of each page where you want to use the server control.

<system.web>
  <pages>
    <controls>
      <add tagPrefix="tag" namespace="namespace" />
      ...
    </controls>
  </pages>
<system.web>

Implement your Control

You can reference the new control in your ASPX code as follows.

  • The tag is the same as the tag you specified in the web.config file
  • The className is simply the name of the class you just created above.

<tag:className runat="server" ... />

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.