?– Note Because we are building a composite control, we inherit from System.UI.Web.CompositeControl,
which implements the INamingContainer interface, to ensure that unique names are generated for each
server control instance on the same page to prevent name conflicts. We discuss why this is necessary in
Chapter 5. CompositeControl also brings in a custom designer automatically via the base class to ensure
proper design-time rendering.
Listing 2-15 shows TableCompCustomControl??™s class file.
Listing 2-15. The TableCompCustomControl Class File
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Text;
namespace ControlsBook2Lib.Ch02
{
[ToolboxData("<{0}:tablecompcustomcontrol runat=server>{0}:
tablecompcustomcontrol>")]
70 CHAPTER 2 ?– ENCAPSULATING FUNCT IONALITY IN A SP.NET
public class TableCompCustomControl : CompositeControl
{
private HtmlTable table;
// properties to access dimensions of HTML table
int xDim;
public int X
{
get
{
return xDim;
}
set
{
xDim = value;
}
}
int yDim;
public int Y
{
get
{
return yDim;
}
set
{
yDim = value;
}
}
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.
Pages:
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138