2009 15 Dec

The ASP.NET environment provides developers with many tools for speeding up the development process. Developers often spend a lot of time writing code which checks the data entered by the user in a web form. ASP.NET validation server controls cut down development time by removing the need to write complex validation code to handle client-side and server-side validation of information entered into a form by a user. The controls do more than just validation; they also perform browser detection to check whether JavaScript is enabled on the client’s browser. If JavaScript is enabled, the control sends the necessary JavaScript code to the client; if JavaScript is not enabled, server-side validation takes place.

ASP.NET offers developers six validation controls available in ASP.NET: the RequiredFieldValidator, the CompareValidator, the RangeValidator, The RegularExpressionValidator, The CustomValidator and the ValidationSummary.

The most frequently used and the most basic is the RequiredFieldValidator. It simply prevents the user from submitting the form without first entering or choosing a value in a required form field. It is often used in conjunction with other validators since, naturally, multiple validators may be applied to the same field.

Next, we have the CompareValidator which performs comparison on the contents of a given form field and another element. The type of comparison can be varied to reflect the type of data the field contains. Thus, for example, if the data is numeric, operators such as equal to, greater than and less than can be used. The comparision will often involve two fields. For example, if your form requests the user’s email address twice to ensure that it has been entered correctly, the CompareValidator can be used to check that the two email address fields contain the same entry.

The RangeValidator performs a special type of comparison; it verifies that the value entered by the user falls within a certain range. It can be used to perform checks within text ranges, number ranges and date ranges.

The RegularExpressionValidator allows you to define a regular expression against which the value entered in a field can be validated. Regular expressions are a widely-used standard for checking that a given string conforms to a certain pattern. They are notoriously arcane but Visual Studio and Visual Web Developer Express make the process easy by providing a Regular Expression Editor which contains regular expressions for matching common types of data such as email address, web URLs as well as postcodes and telephone numbers for several different countries.

The CustomValidator control offers maximum flexibility in performing validation checks, allowing developers to write custom validation code. The code may be client-side or server side.

The final validation server control, the ValidationSummary control is not itself used for validation. Instead, it works in conjunction with the other controls to provide a mechanism for consolidating error messages generated by other validation controls. It is particularly useful for large forms.

Need to master web development using ASP.NET? We offer Microsoft ASP.NET training courses in London and all over the UK.

Possibly related posts: (automatically generated)



  • Share/Save/Bookmark
Published under Computerssend this post
2009 4 Dec

The ASP.NET environment offers a number of built-in solution for displaying information from a database. In ASP.NET, placing a GridView control on your page is one of the simplest ways of displaying databound data. The GridView can be created simply by opening the Database Explorer and dragging the table or view that from which you want to display information. However, the default GridView which is automatically generated in this way almost always needs some tweaking. One typical change you may want to make is to change some of the BoundFields elements to TemplateFields elements.

By default, the GridView displays data using the BoundField object which displays data from a given column in the data source with no real modification. By contrast, any content you desire can be placed inside a TemplateField element. This makes it ideal for setting up validation through the use of validation controls.

If you want a little more freedom in the way information is displayed, try using TemplateFields. These offer great flexibility by allowing you to include a variety of templates to cater for the different states of the conditions arising within the GridView. There are several types of template which may be added inside a TemplateField object; the main ones are described below.

Use the HeaderTemplate to customize the information which will be displayed in the header of the column in which the TemplateField is located.

The ItemTemplate is used to display the information which you want displayed for each row of data when the GridView object is not selected for editing.

The EditItemTemplate is used to hold the information which you want displayed for each row of data when the GridView object is in edit mode. It is here that you would place the controls necessary for validation.

In a typical scenario, you would display the information currently held in the database by adding a TextBox control inside the EditItemTemplate and databind it to the appropriate column from the data source using a statement like Bind(“FirstName”). Inside the same EditItemTemplate, you would then place the necessary validation control. For example, if you want to ensure that the field is not left blank when the form is submitted, you would insert a RequiredFieldValidator control.

Need to learn Building websites with ASP.NET? We offer ASP.NET on-site classes in London and all over the UK.

Possibly related posts: (automatically generated)



  • Share/Save/Bookmark
Published under Computerssend this post
Next Page »