Adding Properties and Methods

Now that you can debug the basic issues with User Controls, let’s add some complexity. One of the nicest things about User Controls is that they can expose properties, making their underlying content more dynamic. They can also expose methods.

Although it’s not a requirement, it is good design practice to implement methods in User Controls only when they are needed to influence the appearance of the content of the User Control itself. Use code-behind methods of your ASP.NET page, .NET components, or Web Services if you need more utilitarian functionality.

Add a Property

Listings 11.3 and 11.4 show your MyControl User Control with a Name property implemented.

Listing 11.3. MyControl with Property (C#)
 <%@ Control Language="C#" ...

Get Debugging ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.