JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

HTML Server Control Classes

When you make an HTML control into a server control, Visual Basic uses the HTML Server Control classes to support that control in code. These classes include such classes as HtmlTextArea for HTML <textarea> controls, HtmlInputButton for HTML buttons created with <input type="button"> elements, HtmlInputText for HTML text fields created with <input type="text"> elements, and so on. Working with HTML server controls in Visual Basic really means working with objects of these support classes, which you can handle directly in Visual Basic code.

When you work with an HTML server control in the Visual Basic IDE, you'll see that its available properties are in lower case, indicating that these properties correspond directly to HTML attributes, and will appear in the .aspx page as you set them. Not all attributes have corresponding properties in the HTML server control classes, but many do, and they're supported by properties of these classes with the usual Visual Basic capitalization. For example, you can set the caption of an HTML server button at design time using the value property, which corresponds to the corresponding HTML <input> element's value attribute. But at run time, back on the server, this attribute is supported by the HtmlInputButton class's Value property. Because we're working with an object of the HtmlInputButton class on the server, the capitalization of property names in server code adheres to the Visual Basic standard, so don't get confused if you see references to both a value property (used in an element at design time or in client-side code) and a Value property (used in the element's corresponding object in server-side code).

It's important to realize that there is not a complete one-to-one correspondence with the HTML Server Control classes and the actual HTML controls you see in the HTML toolbox. For example, the HtmlInputButton class is used not just for buttons, but also for reset buttons (which sets the value in HTML controls back to their default values), as well as submit buttons. These buttons are all created using an HTML <input> element, and they differ only in the setting of the type HTML attribute in that element (a standard button uses <input type="button">, a reset button uses <input type="reset">, and a submit button uses <input type="submit">).

You can find the HTML server control classes in Table 19.1.

Table 19.1: HTML server control classes.

Control

Does this

HtmlForm

Creates an HTML form.

HtmlInputText

Creates an HTML text field. (You also can use this control to create password fields).

HtmlTextArea

Creates an HTML text area (two-dimensional text field).

HtmlAnchor

Creates an <a> element for navigation.

HtmlButton

Creates an HTML button using the <button> element.

HtmlInputButton

Creates an HTML button using the <input> element.

HtmlInputImage

Creates an HTML button that displays images.

HtmlSelect

Creates an HTML select control.

HtmlImage

Creates an HTML <img> element.

HtmlInputHidden

Creates an HTML hidden control.

HtmlInputCheckbox

Creates an HTML checkbox.

HtmlInputRadioButton

Creates an HTML radio button.

HtmlTable

Creates an HTML table.

HtmlTableRow

Creates an HTML row in a table.

HtmlTableCell

Creates an HTML cell in a table.

HtmlInputFile

Creates an HTML file upload control.

HtmlGenericControl

Creates a basic control for an HTML element.

Tip 

Note that there's an HtmlForm class in Table 19.1. HTML programmers know that HTML controls must be in an HTML form to be sent back to the server. However, when creating a Web form in the Visual Basic IDE, you don't have to create the HTML form explicitly—Visual Basic does that as soon as you add input controls to the form.

I'll look at these various classes in more detail and how to work with them in code in this chapter. You can find the notable properties, methods, and events of these classes in the Immediate Solutions section of this chapter. As mentioned, the HTML classes you see in Table 19.1 are not based on the WebControl class we've seen in previous chapters, but on the HtmlControl class. I'll start with that.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor