ASP.NET - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

ASP.NET Controls

ASP.NET Controls

shape Description

Classic ASP codes are based on basic HTML codes, Sometimes it is difficult to separate from HTML and Classic ASP. ASP.NET provides the solution to this problem with the use of server controls. Three types of server controls are

HTML Server Controls

shape Description

HTML server controls are HTML tags recognized only by the server. HTML elements in ASP.NET files and by default, which are treated as text. One need to add a runat=”server” attribute to HTML element to make this elements programmable. Few of the HTML Server Controls are below. TextBox Basic structure of TextBox is below. [html]<asp:TextBox ID="sptxtBox" runat="server"></asp:TextBox>[/html] Button Basic structure of the Button is below: [html]<asp:Button ID="spButton" runat="server" Text="Button" />[/html] Label Basic structure of Label is below. [html]<asp:label id="spLabel"/>[/html]

Validation Server Controls

shape Description

Validation server controls are used to validate the input provided by the user. It will notify the user with an error message if validation fails, Several types of validation controls are used here. Each controls one particular validation.

shape Example

RequiredFieldValidator checks if the particular field is filled or not. It can’t check any expression for that filled. For expression validation, one have to use RegularExpressionValidator. All these validation controls are controlled by CausesValidation property. By default, page validation is performed when a Button is clicked. One can disable validation, when a button control is clicked by setting the CausesValidation property to false. Every time, the ControlToVaidate properties should be filled by the field id of the field which is to be validated. [html]<asp:RequiredFieldValidator ID="sprfvName" runat="server" ControlToValidate="sptxtName" ErrorMessage="Please enter your name">*</asp:RequiredFieldValidator>[/html] In the above code, one RequiredFieldValidator is used for the textbox having id “sptxtName”. In violation of this validation, one error message will be thrown mentioning “Please enter your name”.

shape Conceptual figure

Please see the interaction diagram for a Validation Summary Control.

shape More Info

In the below example, one have used RequiredFieldValidator for the controls textbox, radio button, dropdown list. Submit button will not allow the user to submit the form without filling those values in the mentioned controls.

Web Server Controls

shape Description

Web Server Controls are special ASP.NET elements/tags recognized by the server. Web server controls are created on the server and they require a runat=”server” attribute to work. The id attribute is added to the server control for identification. The id reference can be used for manipulating the server control at run time. These controls don’t necessarily map to any existing HTML elements.

shape Syntax

Basic syntax for Web Server Control is [html] <asp:control_name id="control_id" runat="server" /> [/html]