-->

18 April 2021

ASP.NET Controls

  Asp.Net CS By Example       18 April 2021

ASP.NET Controls

 In this post we are going to learn about ASP.NET Controls. ASP.NET controlsare the heart of 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 contain more than 90 controls, which enable we to do everything from displaying a list of database records to displaying a randomly rotating banner advertisement.

These controls is divided into seven groups:
Sr.No Groups Description
1) Standard Controls Enable to render standard form elements such as buttons,input fields, and labels.
2) Validation Controls Enable 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.
3) Rich Controls Enable to render things such as calendars, file upload buttons, rotating banner advertisements, and multistep wizards.
4) Data Controls Enable to work with data such as database data.
For example, we can use these controls to submit new records to a database table or display a list of database records.
5) Navigation Controls Enable to display standard navigation elements such as menus, tree views, and bread crumb trails.
6) Login Controls Enables to display login, change password, and registration forms.
7) HTML Controls Enable to convert any HTML tag into a server-side control.

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

 <asp:TextBox ID="TextBox1" runat="server" Text="Learn Asp.Net" /> 

 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.

 <input name="TextBox1" type="text" value="Learn Asp.Net" id="TextBox1" /> 

 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 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.

 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, 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. We can, if we prefer, declare the TextBox control like this:

 <asp:TextBox ID="TextBox1" runat="server" Text="Learn Asp.Net" > </asp:TextBox> 

 In this case, the opening tag does not contain a forward slash and an explicit closing tag is included.

logoblog

Thanks for reading ASP.NET Controls

Previous
« Prev Post

No comments:

Post a Comment

Please do not enter any spam link in the comment box.