Cellspacing, "1");
writer.RenderBeginTag(HtmlTextWriterTag.Td);
// write
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.Write("X:" + x.ToString());
writer.Write("Y:" + y.ToString());
// write writer.RenderEndTag();
CHAPTER 2 ?– ENCAPSULATING FUNCT IONALITY IN ASP.NET 67
// write
writer.RenderEndTag();
}
// write
writer.RenderEndTag();
}
// write
writer.RenderEndTag();
}
}
}
The property declarations for the X and Y dimensions of the HTML table demonstrate the
new C# 3.0 syntax available to declare simple properties in a compact manner. Instead of declaring
a private member variable and essentially empty getter and setter methods, this syntax will
create a private member variable automatically:
public int X { get; set; }
public int Y { get; set; }
More interestingly, the Render() method drives the process of rendering the control output.
Rendering the Table Header
The RenderHeader() method is responsible for displaying information about the X and Y properties
inside of an
section. The code to build the tag demonstrates the ability to use
the special Write() methods of the HtmlTextWriter class.
WriteBeginTag() writes the starting portion of a tag, including the opening bracket and the
name of the tag, without closing it:
// write just