Page 56 - DCAP312_WEB_TECHNOLOGIES_II
P. 56

Web Technologies-II



                   Notes                        <body>
                                                <form runat= “server”>
                                                <asp:Button id= “button1” Text= “Click me!”
                                                runat= “server” OnClick= “submit”/>
                                                </form>
                                                </body>
                                                </html>
                                 3.3.1 Generalities of ASP.NET Server Controls
                                 All ASP.NET server controls, including HTML and Web controls plus any custom controls we
                                 create or download, descend from the Control class. The class is defined in the System.Web.
                                 UInamespace; it also is the foundation of all ASP.NET pages.
                                 The Control class is declared as follows:
                                    •  Public class Control: IComponent, IDisposable, IParserAccessor,

                                    •  IUrlResolutionService, IDataBindingsAccessor,
                                    •  IControlBuilderAccessor, IControlDesignerAccessor,
                                    •  IExpressionsAccessor

                                 The  IComponent  interface  defines  the  way  in  which  the  control  interacts  with  the  other
                                 components running in the common language runtime (CLR), whereas IDisposable implements
                                 the common pattern for releasing managed objects deterministically.
                                 3.3.2 Identifying a Server Control

                                 The client ID of a control is generated from the value of the UniqueID property the truly server-
                                 side identifier that ASP.NET generates for each control. The contents of the ClientID property
                                 differ from UniqueID simply in that all occurrences of the dollar symbol ($), if any, are replaced
                                 with the underscore (_). Dollar symbols in the UniqueID string are possible only If the control
                                 belongs to a naming container different from the page.
                                 ASP.NET generates the value for the UniqueID property based on the value of the ID property
                                 that the programmer indicates. If no ID has been specified, ASP.NET auto-generates a name
                                 such as _ctlX, where X is a progressive 0-based index. If the control’s naming container is the
                                 host page, UniqueID simply takes the value of ID. Otherwise, the value of ID is prefixed with
                                 the string representing the naming container and the result is assigned to UniqueID.
                                 3.3.3 Naming Containers

                                 A naming container is chiefly a control that acts as a container for other controls. In doing so,
                                 the naming container generates a sort of virtual namespace so that ASP.NET roots the definite
                                 ID of contained controls in the ID of the naming container. To fully understand the role and
                                 importance of naming containers, consider the following example. Imagine we have a composite
                                 control, such as a user control, that includes a child control like a button. Entirely wrapped by
                                 the user control, the button is not directly accessible by the page code and cannot be given a
                                 distinct and per-instance ID. In the end, the ID of the button is hard-coded in the outermost
                                 control that creates it. What happens when two or more instances of the composite control are
                                 placed on a page? Are we going to have two button child controls with the same ID? This is
                                 exactly what will happen unless we configure the composite control to be a naming container.
                                 The  importance  of  naming  containers  does  not end  here. Imagine  we  have  an instance  of  a
                                 composite control named Control1. Imagine also that the embedded button is named Trigger.


        50                                LOVELY PROFESSIONAL UNIVERSITY
   51   52   53   54   55   56   57   58   59   60   61