Prev | Current Page 296 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

NET framework is the System.Web.UI.
WebControls.Button control. The Button control exists for one reason: to post the page back to
the server and raise events.
We would be remiss if we only reverse-engineered the ASP.NET TextBox control and left
out the Button control, so our next task is to build our own version of the Button control. We
add some bells and whistles along the way, such as the capability for the control to display itself
as a Button or as a hyperlink similar to the LinkButton control in ASP.NET. This new, amazing
Button server control will be named SuperButton for all its rich functionality.
Rendering the Button
The first decision we have to make when building our button relates to how it will render. Because
we decided to render either as an or an tag, we choose to use a
strongly-typed enumeration as a means to configure its display output. We call this enumeration
ButtonDisplay and give it values that reflect how our button can appear in a web form:
public enum ButtonDisplay
{
Button = 0,
Hyperlink = 1
}
208 CHAPTER 5 ?–  SE RVER CONTROL EVENTS
The ButtonDisplay enumeration is exposed from our control through a Display property.
It defaults to a Button value if nothing is passed into the control:
public virtual ButtonDisplay Display
{
get
{
object display = ViewState["Display"];
if (display == null)
return ButtonDisplay.


Pages:
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308