ASP.Net Controls in VB.NET

Introduction

 ASP.NET controls are the heart of the ASP.NET Framework. An ASP.NET control is a .NET class that executes on the server and renders certain content to the browser.
 

The ASP.NET Framework 2.0 contains over 70 controls. These controls can be divided into eight groups as given below:

  • Standard Controls: The standard controls enable us to render standard form elements such as buttons, input fields, and labels.
  • Validation Controls: The validation controls enable us to validate form data before you submit the data to the server. For example, we can use a RequiredFieldValidator control to check whether a user entered a value for a required input field.
  • Rich Controls: The rich controls enable us to render things such as calendars, file upload buttons, rotating banner advertisements, and multi-step wizards.
  • Data Controls: The data controls enable us to work with data such as database data. For example, you can use these controls to submit new records to a database table or display a list of database records.
  • Navigation Controls: The navigation controls enable us to display standard navigation elements such as menus, tree views, and bread crumb trails.
  • Login Controls: The login controls enable us to display login, change password, and registration forms.
  • Web Part Controls: The Web Part controls enable us to build personalizable portal applications.
  • HTML Controls: The HTML controls enable us to convert any HTML tag into a server-side control.

 With the exception of the HTML controls, we declare and use all the ASP.NET controls in a page in exactly the same way. For example, if we want to display a text input field in a page, then you can declare a TextBox control like this:

<asp:TextBox id="TextBox1" runat="Server" />

This control declaration looks like the declaration for an HTML tag. Remember, however, unlike an HTML tag, a control is a .NET class that executes on the server and not in the web browser. When the TextBox control is rendered to the browser, it renders the following content:

<input name="TextBox1" type="text" id="Text1" />

The first part of the control declaration, the asp: prefix, indicates the namespace for the control. All the standard ASP.NET controls are contained in the System.Web.UI.WebControls namespace. The prefix asp: represents this namespace. Next, the declaration contains the name of the control being declared. In this case, a TextBox control is being declared. This declaration also includes an ID attribute. We use the ID to refer to the control in the page within our code. Every control must have a unique ID. It is good practice to use ID attribute to every control even when we don't need to program against it. If we don't provide an ID attribute, then certain features of the ASP.NET Framework won't work. The declaration also includes a runat="Server" attribute. This attribute marks the tag as representing a server-side control. If we neglect to include this attribute, then the TextBox tag would be passed, without being executed, to the browser. The browser would simply ignore the tag. Finally, notice that the tag ends with a forward slash. The forward slash is shorthand for creating a closing </asp:TextBox> tag.  

HAVE A GREAT CODING!


Similar Articles