340 likes | 359 Views
Learn about .NET CLR, CTS, namespaces, and validation controls in the .NET Framework Class Library. Understand intermediate code, structure functions, and how validation controls ensure data integrity.
E N D
BASE CLASS LIBRARY .NET Framework Class Library is the collection of classes, namespaces, interfaces and value types that are used for .NET applications.
CLR • .NET CLR is a run-time environment that manages and executes the code written in any .NET programming language. • It converts code into native code which further can be executed by the CPU.
FUNCTIONS: • It converts program into native code. • Handles Exceptions • Provides type safety • Memory management • Provides security • Improved performance • Language independent • Platform independent • Garbage collection
CTS • The Common Type System (CTS) is a standard for defining and using data types in the .NETframework. • CTS defines a collection of data types, which are used and managed by the run time to facilitate cross-language integration. • In contrast to low-level languages like C and C++ where classes/structs have to be used for defining types often used (like date or time), CTS provides a rich hierarchy of such types without the need for any inclusion of header files or libraries in the code.
CTS is a specification created by Microsoft and included in the European Computer Manufacturer‘s Association standard. • CTS is designed as a singly rooted object hierarchy with System.Object as the base type from which all other types are derived. CTS supports two different kinds of types: • Value Types: Contain the values that need to be stored directly on the stack or allocated inline in a structure. • Reference Types: Store a reference to the value‘s memory address and are allocated on the heap.
NAMESPACES A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it.
INTERMEDIATE CODE • Intermediate language (IL) is an object-oriented programming language designed to be used by compilers for the .NET Framework before static or dynamic compilation to machine code. • The IL is used by the .NET Framework to generate machine-independent code as the output of compilation of the source code written in any .NET programming language. • This term is also known as Microsoft intermediate language (MSIL) or common intermediate language (CIL).
With the help of a suitable just-in-time (JIT) compiler, IL code can be executed on any computer architecture supported by the JIT compiler. • JIT compilation provides better performance, preserves memory, and saves time during application initialization. • The two tools associated with IL code are the MSIL Assembler (Ilasm.exe) and the MSIL Disassembler (Ildasm.exe). • The former(MSIL Assembler) generates a portable executable file from IL code and permits viewing the IL code in human-readable format.
The latter(MSIL Disassembler) converts a portable executable file back to a text file, for viewing and modification. • Both are automatically installed as part of Visual Studio.
VALIDATION CONTROLS • ASP.NET validation controls validate the user input data to ensure that useless, unauthenticated, or contradictory data don't get stored. • ASP.NET provides the following validation controls: • RequiredFieldValidator • RangeValidator • CompareValidator • RegularExpressionValidator • CustomValidator • ValidationSummary
REQUIRED FIELD VALIDATOR • The RequiredFieldValidator control ensures that the required field is not empty. It is generally tied to a text box to force input into the text box. SYNTAX: <asp:RequiredFieldValidator ID="rfvcandidate" runat="server" ControlToValidate ="ddlcandidate" ErrorMessage="Please choose a candidate" InitialValue="Please choose a candidate"> </asp:RequiredFieldValidator>
RangeValidator Control • The RangeValidator control verifies that the input value falls within a predetermined range. • It has three specific properties:
CompareValidator Control • The CompareValidator control compares a value in one control with a fixed value or a value in another control. • It has the following specific properties:
RegularExpressionValidator • The RegularExpressionValidator allows validating the input text by matching against a pattern of a regular expression. The regular expression is set in the ValidationExpression property. • The following table summarizes the commonly used syntax constructs for regular expressions:
Apart from single character match, a class of characters could be specified that can be matched, called the metacharacters.
Quantifiers could be added to specify number of times a character could appear.
Custom validator • The CustomValidator control allows writing application specific custom validation routines for both the client side and the server side validation. • The client side validation routine should be written in a scripting language, such as JavaScript or VBScript, which the browser can understand. • The server side validation routine must be called from the control's ServerValidate event handler. The server side validation routine should be written in any .Net language, like C# or VB.Net.
Validation Summary • The ValidationSummary control does not perform any validation but shows a summary of all errors in the page. • The summary displays the values of the ErrorMessage property of all validation controls that failed validation. • The following two mutually inclusive properties list out the error message: • ShowSummary : shows the error messages in specified format. • ShowMessageBox : shows the error messages in a separate window.
View state • State management means to preserve state of a control, web page, object/data, and user in the application explicitly because all ASP.NET web applications are stateless, i.e., by default, for each page posted to the server, the state of controls is lost.
View state is the page-level state management technique used in the ASP.NET page framework to retain the value of controls and page between round trips. • Data objects such as hash tables, strings, array objects, array list objects, Boolean values and custom-type converters can be stored in view state. • View state is ideally used when the data to be preserved is relatively small and the data need not be secured
By default, the view state is switched on and regardless of whether used during a postback, it serializes the information in every control found on the page. • To disable the view state for a single control, the EnableViewState property needs to be set as false. • The attribute EnableViewStateMac is provided to detect any corruption attempt or technique on the view state.
Advantage: • The mean features of view state are to store the values of control properties and pages found in the concerned page, without the help of a session, preserve the value of the control after the postback operation and to create a custom view state provider for storing view state information in a database. • Disadvantages: • For large amounts of data, the performance is not optimal, as large values could potentially cause view state to be slow • View state can only store values for same page only.
WEB CONTROLS Webcontrol class: • Serves as the base class that defines the methods, properties and events common to all controls in the System.Web.UI.WebControls namespace. • Some of the properties are mentioned below :-
INPUT CONTROL • Input controls let the user enter text data into the application. ASP.NET supports only one input web control: the TextBox. The TextBox behaves like a single-line or multiline edit control, depending on the value of its TextMode property.
DISPLAY CONTROLS • Display controls simply render text or images to the browser.
ACTION CONTROLS • Action controls allow users to perform some action on that page, such as navigating to a different URL, submitting a form, resetting a form's values, or executing a client script.
SELECTION CONTROLS • Selection controls allow the user to select one or more values from a list. They include both the CheckBox and RadioButton controls, which are designed to work in a group.