1 / 20

Asp.NET Core Server Controls

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

violet
Download Presentation

Asp.NET Core Server Controls

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Asp.NET Core Server Controls

  2. Lecture Overview • Understanding the types of ASP.NET controls • HTML controls • ASP.NET (Web) controls

  3. The runat Attribute • The runat attribute makes a server control a server control • This is true for both HTML and Web controls • All tags without the runat attribute set are copied verbatim to the output stream (HTTP response) • <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>

  4. Categorizing Server Controls ASP.NET CONTROLS WEB CONTROLS HTML CONTROLS

  5. Categorizing Server Controls • HTML controls • always map to HTML tags • All attributes are strictly compatible with XHTML • They allow you to perform ‘some’ server side processing • Web Controls (ASP.NET server controls) • Are implemented by the ASP server as .NET Framework classes having a common .NET programming interface

  6. Generalities • HTML controls and Web controls can sometimes to do the same thing • HTML controls can be used to conditionally create client-side script • Web controls generally provide a ‘richer’ programmatic interface

  7. HTML Controls (Example <head>) • A <head> tag can be designated runat=“server” • The Header property maps to the HTML <head> tag • <head runat="server">

  8. HTML Controls (Example <head>) • Store a value in the page header protected void Page_Load(object sender, EventArgs e) { Header.Title = "IS 460 HTML Control Demo " + System.DateTime.Now.ToString(); }

  9. HTML Controls (Example <head>) • The following <head> tag is emitted from the server-side control <head> <title> IS 460 HTML Control Demo 9/7/2009 12:09:10 PM </title> </head>

  10. HTML Controls <a> • The HTMLAnchorclass implements <a> tags • <a> tags designated runat=“server” and having an id will be seen by the server <a id="BusinessNews" runat="server"></a>

  11. ASP.NET Server Controls • These are unique to ASP.NET • All are contained in the System.Web.UI.WebControls namespace • All derive from WebControl • runat=“server” attribute is required or the markup will be rendered verbatim • They are not the same as HTML controls • The programming interface is more intuitive

  12. ASP.NET Server Controls (Properties 1) • ID – Name that will be used to reference the control instance programmatically • Page – Page object on which the control resides • Parent – parent control instance • Visible – Make the control instance visible or invisible • EnableViewState defines whether contents are persisted through view state

  13. ASP.Net Server Controls (Properties 2) • The Style property contains references a collection of CSS style MyControlStyle[“border-color”] = blue; • The CssClass contains the name of a defined CSS class • txtStyleDemo1.CssClass = "TextBox"

  14. ASP.NET Server Controls(Methods) • Focus – sets input focus to the control instance when it is rendered • HasControls – denotes whether this control instance has child controls • Controls – a collection of child controls • DataBind – binds the control instance to a data source

  15. ASP.NET Server Controls (Events) • Same page and control events discussed in the previous chapter • Init – First step in the life cycle • Load – occurs when the control is loaded into the page • PreRender – fires just before the page is rendered • Unload – control has been rendered. Use only to close files or release connections

  16. Other Control Characteristics • Adaptive rendering allows controls to render differently based on the browser • Control properties can be declared for different browsers, as follows: <asp:TextBox ID="TextBox4" runat="server" ie:text="IE Button" mozilla:text="Firefox button"></asp:TextBox>

  17. Control State (Introduction) • State information must often be persisted across page requests • Control state is like view state • You generally don’t mess with the control state

  18. Core Web Controls (Introduction) • Editable controls include check boxes, radio buttons, text boxes, labels, etc… • There is a Table control that implements a table container • TableCell and TableRow implement cells and rows • See Demo • HyperLink and LinkButton implement links • Use the FileUpload control to upload files

  19. Button Controls (Introduction) • CausesValidation determines whether a validation is performed when the button is clicked. ValidationGroup also controls validation • More next time • Text contains the text that appears in the button • Visible property displays or hides the button

  20. Other Controls • The Panel control acts as a container for other controls • The View control creates a group of interchangeable panels

More Related