Page 40 - DCAP312_WEB_TECHNOLOGIES_II
P. 40

Web Technologies-II



                   Notes            •  <%@  Register  TagPrefix=  “uc1”  TagName=  “SampleUserControl”  Src=  “/Portals/0/
                                      SampleUserControl.ascx” %>. This code registers the control with the current aspx page.
                                    •  <uc1:SampleUserControl id= “SampleUserControl1” runat= “server”><uc1:SampleUser
                                      Control>. This entry will be found inside the <form> .. </form> tag.
                                    •  Build the application.
                                    •  Select and view the TestPage.aspx in the browser. This will show the aspx page with the
                                      control loaded with it.
                                 Now if we need we can change the background color to Gray, by adding the property in the
                                 control as follows.

                                 <uc1:SampleUserControl BackColor= “Gray” id= “SampleUserControl1” runat= “server”></
                                 uc1:SampleUserControl>
                                 Now if the application is built, the testpage.aspx will show our user control with a gray
                                 background.
                                 2.2.2 Advantages of a Web User Control

                                 The biggest advantage of the Web User controls is that they can be shaped as a site pattern
                                 and used all through the site. For example they can be complete to contain the Menu/Link
                                 arrangement of a site and can be used at all the previous aspx pages.
                                 This means the following:

                                    •  If the website introduces a new site-wide link within the current layout/structure, it is
                                      enough if we put it on the user control once. All pages will be updated once if the web
                                      user control is used in them.
                                    •  If there is any link to be corrected, it can be done once at the server side.
                                    •  The .ascx files can either be used as a simple alternative to the plain HTML or they can
                                      also be used to respond to events: This means even custom code can be created against
                                      them and put in the code behind files.
                                 2.2.3 Drawbacks / Disadvantages
                                 Though  the  User  controls  offer  a  flexibility  of  having  site  wide  modifications,  if  the  whole
                                 structure of the site changes, the HTML/aspx code of all the pages should be modified. But as
                                 long as the site maintains a same layout, then Web User controls is the number one choice for
                                 maintaining the generic layout of the site.
                                 Another disadvantage is It cannot be just be simply referenced for using in a different project.
                                 If we want to use this User Control in a different project, we have to copy the file and modify
                                 the namespace to the host namespace name.

                                 Self Assessment Questions
                                 Multiple Choice Questions
                                    1.  The .Net framework ......... can be downloaded from Microsoft’s .NET framework developer
                                      centre.
                                       (  a)  SDK                      (b)  CLR
                                       (  c)  CRM                      (d)  All of these
                                    2.  The object-oriented nature of C# ..................
                                       (  a)  middle-level language    (b)  low level language
                                       (  c)  high level language      (d)  None of these



        34                                LOVELY PROFESSIONAL UNIVERSITY
   35   36   37   38   39   40   41   42   43   44   45