Home > Articles > Web Development > ASP.NET

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Using Your Control

One of the things you'll want to do before deploying the control is to specify its tag prefix that appears in the HTML of the web form when you add the control. Add the following TagPrefix attribute to the top of the RatingControl code:

[assembly: TagPrefix("Mayo.Web.Controls", "mayo")]

You deploy rendered custom controls by adding their containing DLL to the Tool Palette:

  1. Right-click the Tool Palette and select Installed .NET Components.

  2. Click the Select an Assembly button.

  3. Locate the DLL containing the rendered custom control. This will add the control to the Installed .NET Components list, and you'll see it in the Tool Palette under the General section when you close the dialog box.

When you drag-and-drop the control onto your web form, it will add a new Register directive to the HTML:

<%@ Register
  TagPrefix="mayo"
  Namespace="Mayo.Web.Controls"
  Assembly="RatingControl" %>

Notice that it has the TagPrefix that was added as an assembly attribute to the RatingControl code. Here's the HTML for the control:

<mayo:ratingcontrol id=ratingControl1 runat="server"
  text="Rate this Article (5 is highest):">
</mayo:ratingcontrol>

This uses the TagPrefix and type name of the control to define the control. The text attribute reflects a change made in the Object Inspector in the designer. Figure 1 shows a sample web form with the RatingControl control added.

Figure 1Figure 1 The RatingControl control added to a web form. It appears and is handled just like the ASP.NET controls that come with the .NET Framework.

Figure 1 shows the RatingControl control on the design surface. Additionally Label controls are populated by event handlers in the code-behind of this web form. The event handlers are hooked up to a couple of events on RatingControl that send out notifications when the button is clicked and when the rating changes.

  • + Share This
  • 🔖 Save To Your Account