Page 218 - DCAP408_WEB_PROGRAMMING
P. 218

Web Programming




                    Notes          In Figure 8.3, the first stage deals with Web control initialization. We  don’t need to be  too
                                   concerned about this stage in our own programming tasks.
                                   Our code is frequently involved in the second stage of Web forms processing, when the ASP.NET
                                   infrastructure fires the Load event in the Page class. As Listing 1 shows, we can use the Page_Load
                                   event (Lines 20-30) to change the contents of controls or to perform any other kinds of processing
                                   before a page is rendered. If the page posts back to itself (that is, if the user clicks the Convert
                                   button), the Page_Load event will fill in zeros if the user leaves any field blank (Lines 22-27).

                                   The third stage of Web forms processing is for control event handling, which happens only if the
                                   user manipulates one of the Web controls on the page. This stage won’t happen if this is the first
                                   time the user is browsing this particular page. In above Listing, the On Convert method is called
                                   during this stage (Lines 32-38). Note that event handling happens after the Page_Load event. In
                                   the fourth stage, the HTML for the page is rendered. This process involves calling the Render
                                   method for the page, which will call the Render method for every control, among other things.




                                     Notes  Listing 1 doesn’t contain an explicit Render method because the page class and Web
                                     control classes have default implementations for it already. We will need to override the
                                     Render method only if we want to customize the exact HTML that each class produces.
                                     In the last stage, the Page_Unload event for every gets called. We can use the Unload event
                                     to clean up database connections and other objects that have to be closed explicitly, for
                                     example. (Listing 1 also doesn’t define the Page_Unload event because it doesn’t need to
                                     clean up any objects.)

                                   Self Assessment

                                   Fill in the blanks:
                                   13.  A …………………… is another name for an ASP.NET page.

                                   14.  A Web form may be processed after the user interacts with one of the ……………………
                                       controls.
                                   15.  A Web form is rendered when the user initially browses to the ……………………  file.


                                     

                                     Caselet     Get the Writing Craft Right

                                     T     ECHNICAL  Writing Process and Product, by  Sharon and Steven Gerson, offers
                                           numerous tools for writing successful correspondence on the job. A sampler:

                                         For most of us, when we get out that piece of paper or turn on the computer, one of
                                          two things happens.

                                     Either we stare at the blank page or screen until beads of sweat form on our foreheads and
                                     we break out in hives because of the dreaded blank page syndrome, or we wander about
                                     aimlessly for several pages.
                                         A good rule of thumb is to write to express, not to impress; write to communicate,
                                          not to confuse. If your reader must use a dictionary, you’re not writing clearly.

                                                                                                         Contd...



          212                               LOVELY PROFESSIONAL UNIVERSITY
   213   214   215   216   217   218   219   220   221   222   223