Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [139]

By Root 5742 0
events—Click and Command—that are raised when the control is clicked. The OnClick event handler provides you with an ImageClickEventArgs data structure that contains information about the coordinates for the location at which the image is clicked.

The OnCommand event handler makes the ImageButton control behave like a command button. A command button has an associated name that you can control through the CommandName property. If you have multiple ImageButton controls on the same page, the command name allows you to specify which one is actually clicked. The CommandArgument property can be used to pass additional information about the command and the control.

Finally, the ImageMap control deserves a few words. In its simplest and most commonly used form, the control displays an image on a page. However, when a hot-spot region defined within the control is clicked, the control either generates a postback to the server or navigates to a specified URL. The hot spot is a clickable region within the displayed image. The hot spot is implemented with a class that inherits from the HotSpot class. There are three predefined types of hot spots: polygons, circles, and rectangles.

Check Boxes and Radio Buttons


Check boxes and radio buttons are implemented through the tag and with the type attribute set to checkbox or radio. Unlike the HTML control versions, the Web control versions of check boxes and radio buttons let you specify the associated text as a property. The HTML elements and corresponding HTML controls lack an attribute whose content becomes the text near the check box or radio button. In HTML, to make the text near the check box or radio button clickable, you have to resort to the

Neither the HtmlInputCheckBox nor the HtmlInputRadioButton control adds a label, which leaves you responsible for doing that. The counterparts to these Web controls, on the other hand, are not bound to the HTML syntax and do precisely that—they automatically add a Text property, which results in an appropriate

It results in the following HTML code:

Text Controls


The fastest way to insert text in a Web page is through literals—that is, static text inserted directly in the ASPX source. This text will still be compiled to a control but, at least, the number of dynamically created literal controls is the minimum possible because any sequence of consecutive characters are grouped into a single literal. If you need to identify and manipulate particular strings of text programmatically, you can resort to a Literal control or, better yet, to the richer Label control. Modifiable text requires a TextBox.

Over the years, ASP.NET text controls went through a number of minor changes but preserved core functionalities. In particular, I want to mention that the TextBox class implements two interfaces as a way to logically group its capabilities. Frankly, this aspect is not that relevant for the ASP.NET developer seeking coding tips and tricks. It makes a good statement, however, about the design of the control and, all in all, represents a good example of programming to learn from and reuse in our own classes. (This is related to one of the core design principle I’ll cover in Chapter 13, —the Interface Segregation Principle.)

The two interfaces implemented by TextBox classes are ITextControl and IEditableTextControl. The former includes the sole Text property and is implemented by Literal, Label, TextBox, and list controls. The latter interface defines the TextChanged event and is specific to TextBox and list controls.

Speaking of text controls, it is also worth mentioning an accessibility feature of the Label control—the AssociatedControlID property. The property takes the ID of a control in the page—typically, an input control such

Return Main Page Previous Page Next Page

®Online Book Reader