Page 65 - DCAP312_WEB_TECHNOLOGIES_II
P. 65

Unit 4: Advanced Server Controls



            expect other web sites to perform with the same elegance as they do. When a web site does   Notes
            not perform with the same elegance the user will often move onto another web site that does.
            Those popular applications have raised the bar for what is an acceptably user-friendly web site.
            Because our users are demanding a web site experience that essentially uses Ajax and we build
            our ASP.NET web sites using server controls, we need a way of easily creating server controls
            that not only encapsulate browser appearance and server functionality, but also include Ajax
            functionality so that the server control itself is Ajax-enabled.
            Taking a step back for a moment, unlike other technologies we might have read books on, ASP.
            NET AJAX server controls do not provide we with anything that we could not already do. We
            have always been able to embed Ajax-functionality into server controls it was just a real pain.
            There were a few different methods we could use to include the JavaScript with our server
            control such as embedding it as a resource, but we eventually ended up having to do the same
            three tasks. To make our server control have some serious client capabilities we always had to
            concatenate strings together to form JavaScript statements and functions, write browser sniffing
            statements to make sure that the JavaScript was cross-browser compatible, and add attributes
            or render out Html that attached the JavaScript functionality to the client versions of our server
            controls. It was not impossible, but it was error-prone and there was always this mingling of
            server code and JavaScript that was hard to maintain and even harder to read.
            Furthermore, if we had multiple server controls that had client capabilities it was difficult (but
            not  impossible)  to  ensure  that  the  client  functions  that  each  server  control  required  did  not
            overwrite each other when rendered on the browser. Tracking down that problem was always
            a fun hour or so. The difficulty grew exponentially if we wanted to include a mechanism for
            asynchronously communicating with the server when the user pressed a button embedded in the
            server control. Even with a helper communication library there were always tricks to getting our
            control to communicate properly with the server. These hindrances were problematic enough to
            lead to some bad programming habits and bad code as well as scare programmers away from
            even attempting to include Ajax-functionality in their server controls. These problems are what
            Microsoft’s ASP.NET AJAX solves.

            4.1 HTML Server Controls

            The HTML server controls are basically the inventive HTML controls but improved to enable
            server side processing. The HTML controls like the subtitle tags, anchor tags and contribution
            elements are not processed by the server but sent to the browser for show.
            They are specifically converted to a server control by adding the attribute runat= “server” and
            adding an id attribute to make them available for server-side processing.
            For example, consider the HTML input control:
                     <input type= “text” size= “40”>
                     It could be converted to a server control, by adding the runat and id attribute:
                     <input type= “text” id= “testtext” size= “40” runat= “server”>

            4.1.1 Advantages of Using HTML Server Controls
            Though  ASP.Net  server  controls  can  execute  every  job  accomplished  by  the  HTML  server
            controls, the later controls are useful in the following cases:
               •  Using static tables for layout purposes.
               •  Converting a HTML page to run under ASP.NET.





                                             LOVELY PROFESSIONAL UNIVERSITY                                    59
   60   61   62   63   64   65   66   67   68   69   70