1 of 9

Chapter 2

2 of 9

ASP.NET Server Controls

Types of Server Control

    • HTML Server Controls (Traditional HTML tags)
    • Web Server Controls (New ASP. NET tags)
    • Validation Controls
    • User Define Controls

​

3 of 9

ASP.NET Server Controls (Cont..)

HTML server controls

    • These controls are basically the original HTML controls but enhanced to enable server side processing.
    • To make these elements programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the element should be treated as a server control.
    • All HTML server controls must be within a <form> tag with the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server.
    • You have all the HtmlControl class’s properties and methods available such as, ID, EnableViewState, Disabled, Style, and some more.

​

​

4 of 9

HTML server controls (Cont..)

HtmlControl Class

    • The HtmlControl base class is used for those HTML classes that are focused on HTML elements that can be contained within a single node. Such as <img>, <input>, and <link> elements.

(These elements are derived from HtmlControl Class)

HtmlContainerControl Class

    • A class specifically designed to work with HTML elements that require a closing tag.
    • HTML elements such as <a>, <form>, and <select>, require an opening and closing set of tags.
    • These controls have some extra properties like InnerText and InnerHtml.
    • InnerHtml: Enables you to specify content that can include HTML elements to be placed between the opening and closing tags of the specified control.
    • InnerText: Enables you to specify raw text to be placed between the opening and closing tags of the specified control.

(These elements are derived from HtmlContainerControl Class)

HtmlGenericControl Class

    • Using the HtmlGenericControl class, you can get server-side access to the <meta>, <p>, <span>, or other elements that would otherwise be unreachable.

​

5 of 9

​

  • Project Title

6 of 9

Manipulating Pages and Server Controls with JavaScript

    • Apply JavaScript directly to the controls on your ASPX page.
    • Using Page.ClientScript.RegisterClientScriptBlock
      • The RegisterClientScriptBlock method allows you to place a JavaScript function at the top of the page.
      • RegisterClientScriptBlock(type, key, script, script tag specification)
    • Using Page.ClientScript.RegisterStartupScript
      • RegisterStartupScript places the script at the bottom of the ASP.NET page instead of at the top.
      • RegisterStartupScript(type, key, script, script tag specification)

7 of 9

Manipulating Pages and Server Controls with JavaScript (Cont..)

    • Using Page.ClientScript.RegisterClientScriptInclude
      • You can register the script files on your ASP.NET pages using the RegisterClientScriptInclude method.
      • Page.ClientScript.RegisterClientScriptInclude(type, key, url)

​

8 of 9

Comparing a Typical Postback to a callback

  • Postback
    • A postback occurs when a request is sent from the client to the server for the same page as the one the user is currently viewing.
    • When a postback occurs, the entire page is refreshed.
    • Callback
    • A callback occurs when a request is sent from the client to the server for which the page is not refreshed.
    • Only a part of it is updated without any flickering occurring on the browser

9 of 9

Common Properties

    • Access Key
      • Alt + key.
    • Attributes
      • Enables you to define additional attributes for a Web server control that are not defined by a public property.
    • Disabled
      • Allows you to get or set whether the control is disabled using a Boolean value.
    • Visible
      • Specifies whether the control is visible on the generated page.