Page 71 - DCAP312_WEB_TECHNOLOGIES_II
P. 71

Unit 4: Advanced Server Controls



            process. One of the first steps is to understand what validating data means. Validating, in this   Notes
            case, does not mean that if John Doe types his name into the form field of a text box as Fred
            Doe the computer sends an alert to inform us that the data is untruthful. No, we still do not
            have the capability to find out whether a statement is true.
            Validation is testing to determine whether the user entered something into the field. After we
            determine that something was entered, we can then also check to see whether what was entered
            is a number or a character and if it is in the correct format. From there, we can compare user
            input in different fields or against values that might be held in other repositories, such as a
            database. Data collection on the Internet is one of its most important features, so we must make
            sure that the data we collect has value and meaning. We ensure this by eliminating any chance
            that the information collected does not abide by the rules we outline.

                          When creating a client-side validation function, be sure to also include the
                          functionality of the server-side validation function. If you create a client-side
                          validation function without a corresponding server-side function, it is possible
                          for malicious code to bypass validation.

            4.2.1  Understanding the Difference between Server-Side and Client-Side
                 Validation
            Many persons new to ASP.NET do not know the dissimilarity between client-side and server-
            side justification. We must understand these two different ways of validating the data user’s
            contribution into a Web form. After the user enters data into a Web form, clicks the Submit
            button, and sends the form data to the server as a request, we can perform server-side validation
            on the data. If the data is incorrect or not valid, we can send back a response stating this. If,
            however, when the user clicks the Submit button, a scripting language that is part of the overall
            HTML page is initiated to check the validity of the data before it is sent to the server, this is
            client-side validation.
            It was a lot easier to appreciate the difference between these forms of corroboration when we
            coded Active Server Pages 3.5 because, as the programmer, we in person performed approximately
            all data validation. We our self either programmed it to be client-side or server-side.
            When we used server-side validation with ASP 3.5, if something the user entered was wrong,
            we could repost the form and ask the user to correct the information in that particular field of
            the form. Sometimes, we carried the correct input from the other fields back to the form page,
            and populated the fields for the users so they did not have to re-enter the same information
            again. Some sites on the Internet do not carry this inputted information back to the form page,
            and the user is then required to enter all the information into the form a second time. Obviously,
            this may cause people to leave our site for another. The bad thing about server-side validation
            is that it requires trips back and forth to the server. This takes a lot of resources and makes
            for a slower-paced form for the user. Nothing is more annoying to a user who is on a dial-up
            connection than clicking the Submit button on the form and then waiting for 20 seconds to find
            out that they did not enter their password correctly.
            The other option for form validation is to put some client-side JavaScript or VBScript at the
            top of the ASP page that checks if the information in the fields is correct. This takes care of the
            problem of making unnecessary trips to the server, but it requires another language to learn
            and manage. JavaScript is a great language, but takes a lot of time to master, and there are
            always problems getting our JavaScript code to work on different browsers. Example shows us
            an example of using client-side JavaScript to perform form validation.

                           Client-Side JavaScript for form Validation
                           <script language= “javascript”>
                           <!--

                                             LOVELY PROFESSIONAL UNIVERSITY                                    65
   66   67   68   69   70   71   72   73   74   75   76