Asp.NET Core Server Controls

Click here to load reader

  • date post

  • Category


  • view

  • download


Embed Size (px)


Asp.NET Core Server Controls. Lecture Overview. Understanding the types of ASP.NET controls HTML controls ASP.NET (Web) controls. The runat Attribute. The runat attribute makes a server control a server control This is true for both HTML and Web controls - PowerPoint PPT Presentation

Transcript of Asp.NET Core Server Controls


Asp.NET Core Server ControlsSlide #Lecture OverviewUnderstanding the types of ASP.NET controlsHTML controlsASP.NET (Web) controlsSlide #The runat AttributeThe runat attribute makes a server control a server controlThis is true for both HTML and Web controlsAll tags without the runat attribute set are copied verbatim to the output stream (HTTP response)

Slide #Categorizing Server ControlsASP.NET CONTROLSHTML CONTROLSWEB CONTROLSSlide #Categorizing Server ControlsHTML controls always map to HTML tagsAll attributes are strictly compatible with XHTMLThey allow you to perform some server side processingWeb Controls (ASP.NET server controls)Are implemented by the ASP server as .NET Framework classes having a common .NET programming interfaceSlide #GeneralitiesHTML controls and Web controls can sometimes to do the same thingHTML controls can be used to conditionally create client-side scriptWeb controls generally provide a richer programmatic interface We will focus on Web controls in this lectureSlide #HTML Controls (Overview)HTML controls are similar to ordinary HTML controlsHowever, with the runat=server attribute addedASP.NET adds a programmatic way to interact with the control instances on the server

ASP.NET controls are part of the System.Web.UI.HtmlControls namespaceSlide #HTML Controls (Interface)All HTML controls inherit from the HtmlControl classThe properties are simpleAttributes returns a collection of attribute / key value pairsStyle gets a CSS collection of applied CSS propertiesDisabled indicates whether the control is disabled

Slide #HTML Controls (Categories)Figure 6-2 on page 239 shows the control categoriesHtmlInputControl These represent the variations of the tagHtmlContainerControl These are Tables and other controls that contain other controlsOther Other controls such as Slide #HTML Controls The HTMLAnchor class implements tags tags designated runat=server and having an id will be seen by the server

Slide #HTML Controls The href property contains the linkStore the text in InnerHtml or InnerTextBusinessNews.HRef="";BusinessNews.Title = Business news channel";BusinessNews.InnerHtml = "BusinessNews";Slide #HTML Input ControlsAll input controls derive from HtmlInputControlName is the read-only property containing the control nameType property mirrors the Type attributeValue contains text appearing in the control instanceSlide #The ServerChange eventIt fires for most HTML controls to denote that the controls contents have changed from one postback to the nextUse for check boxes, radio buttons, text boxes, etc.Slide #ASP.NET Server ControlsThese are unique to ASP.NETAll are contained in the System.Web.UI.WebControls namespaceAll derive from WebControlrunat=server attribute is required or the markup will be rendered verbatimThey are not the same as HTML controlsThe programming interface is more intuitiveSlide #ASP.NET Server Controls (Properties 1)ID Name that will be used to reference the control instance programmatically (Its the Name property that you are used to in VB)Page Page object on which the control residesParent parent control instanceUse for container controlsVisible Make the control instance visible or invisibleEnableViewState defines whether contents are persisted through view state

Slide #ASP.Net Server Controls (Properties 2)The Style property contains references to a collection of CSS styleMyControl.Style[border-color] = blue;

The CssClass property contains the name of a defined CSS classtxtStyleDemo1.CssClass = "TextBox"

Slide #ASP.NET Server Controls(Methods)Focus sets input focus to the control instance when it is renderedHasControls denotes whether this control instance has child controlsControls a collection of child controlsDataBind binds the control instance to a data sourceSlide #ASP.NET Server Controls (Events)Same page and control events discussed in the previous chapter

Init First step in the life cycleLoad occurs when the control is loaded into the pagePreRender fires just before the page is renderedUnload control has been rendered. Use only to close files or release connectionsSlide #Other Control CharacteristicsAdaptive rendering allows controls to render differently based on the browserControl properties can be declared for different browsers, as follows:

Slide #Control State (Introduction)State information must often be persisted across page requestsControl state is like view stateYou generally dont mess with the control stateSlide #Help Pages (Note)

Slide #Core Web Controls (Introduction)Editable controls include check boxes, radio buttons, text boxes, labels, etcThere is an ASP Table control that implements a table containerTableCell and TableRow implement cells and rowsSee DemoHyperLink and LinkButton implement linksUse the FileUpload control to upload filesSlide #Button Controls (Introduction)CausesValidation determines whether a validation is performed when the button is clicked. ValidationGroup also controls validationMore next timeText contains the text that appears in the buttonVisible property displays or hides the buttonSlide #Basic ControlsThe TextBox and Label controls are similar to their desktop equivalentsCheck boxes operate similarly tooYou will notice that there is no scroll barSlide #List ControlsMany controls work with listsThey all work similarlyListBoxDropDownListCheckListBoxRadioButtonList

Slide #The ListBox ControlLike the desktop equivalent, SelectedIndexChanged fires when an item is selectedEach item in the ListBox is a ListItemThese can be added at design time or at run timeSet AutoPostBack, as necessary

Slide #The ListBox ControlPropertiesSelectedIndex 0-based index of the item selectedSelectedItem Text of the selected itemSelectedValue An associated value (used with data bindingSet SelectionMode to allow selection of multiple itemsSlide #Container ControlsThey are used to group other controlsMake the sub controls visiblePerform similar actions to all controls in the groupPanel groups child controlsMultiView acts as a container for View controlsThere are others

Slide #The Panel ControlSimply put, it groups other controlsUse it toOrganize controls visuallyMake groups of controls visible or invisibleCreate scrollable regionsSlide #The Panel ControlSet the ScrollBars property to enable/disable scrollbarsSet the Visible property to hide or make visible the controlSlide #The View and MultiView ControlsUse these to create multiple views of informationWorks something like a wizardCreate one MultiView controlCreate many View controls inside of the MultiViewFor each View control create a button and set the CommandName and CommandArgument propertiesSlide #Radio ButtonsThey work like their desktop equivalentsPut in a RadioButtonList to create button groupsSelectedIndex contains the index of the selected buttonThe value is -1 if nothing is selectedSlide #