Page 72 - DCAP312_WEB_TECHNOLOGIES_II
P. 72

Web Technologies-II



                   Notes                        Function CheckForm(form)
                                                {
                                                for(var intCtr = 0; intCtr <= (form.elements.length - 5);
                                                ++intCtr)
                                                {
                                                var temp = form.elements[intCtr];
                                                if(temp.type == “text” && temp.value == “”)
                                                {
                                                alert( “Please Enter All Information!”);
                                                temp.focus();
                                                return false;
                                                }
                                                }
                                                return true;
                                                }
                                                //-->
                                                </script>
                                 This sample piece of JavaScript does some validation, but it does not check for all the information
                                 that we might need on the form we are building. This piece of code determines only whether
                                 the user entered anything at all in all five fields within the form. It does not determine whether
                                 the user entered an actual e-mail address within the e-mail address text box, whether the user
                                 entered  a  number  between  two  given  numbers,  or  whether  the  password  and  the  confirm
                                 password text boxes match. After awhile, we can see that we need many JavaScript functions
                                 to obtain the level of form validation required.
                                 4.2.2 .NET to the Rescue

                                 Developers who used classic Active Server Pages 3.5 to develop Web pages might keep in mind
                                 that they used to use up a considerable quantity of their time initial validation workings in their
                                 page. It was time consuming if we did it right. It was most efficient to do the validation of the
                                 form on the client-side to limit the number of requests and responses required to work through
                                 an application. However, we were never quite sure if the requesting browser would understand
                                 the scripting code that we used for the validation. So, it was usually better, especially for critical
                                 Web applications, to bring the validation to the server.

                                 ASP.NET has distorted this by giving us the potential to use the corroboration server controls
                                 that are provided with the other new controls at our disposal. What makes these validation
                                 server controls effective is that when an ASP.NET page containing these controls is requested,
                                 it is the ASP.NET engine that decides whether to perform the validation on the client or on the
                                 server depending on the browser that is making the request. Therefore, our page’s functionality
                                 changes depending on the requesting browser—thus enabling us to make our Web pages the
                                 best they can possibly be rather than dummying-down our Web applications for the lowest
                                 common denominator. Validation server controls are the only type of ASP.NET server controls
                                 that also generate client-side script. All the other controls work with the idea of making post
                                 backs to the server (a request to the server to get a response).
                                 Six different validation server controls are available for ASP.NET:
                                    1.  RequiredFieldValidator

                                    2.  CompareValidator

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