This document discusses different types of server controls in ASP.NET including ASP.NET Web Server Controls, HTML Server Controls, and creating server controls dynamically. It provides examples of common controls like textboxes, buttons, dropdown lists and describes how controls can be referenced and handled via server-side code behind files using properties and events. Validation controls are also mentioned.
1. Types of Server Controls
ASP.NET Web Server Controls
HTML Server Controls
Creating Server Controls Dynamically
2. With ASP. Net, these are any controls that run in the
server space.
o Handled by ASP. Net runtime
o Must have runt=“server” attribute within the ASP. Net web form
o Always identified with the “ID” attribute (also mandatory with
ASP. Net web controls)
Properties, events, etc. can all be handled by server-side
code
4. • Like the ASP. Net Page object
(System.Web.UI.Page), web controls maintain
the same event processing
– Init, PreRender, Load, etc
• If AutoPostBack is set on the control, the
event will be fired immediately (causes an
automatic postback), otherwise, the event will
fire upon next page postback
• Checkbox
– Check Changed()
• Button
– Click(), Command()
• Dropdown List
– Text Changed(), SelectedIndexChanged()
5. • System.Web.UI.HtmlControls
– Ex: HtmlButton, HtmlTable, HtmlInputText
• These are ASP. Net HTML server controls
– Rendered as:
– <button />, <table />, <input type=“text” />
6. • The HtmlControls collection allows the
programmer access to HTML elements (and their
properties, etc.) from server-side code
– Hence, page content (HTML elements) can also be
dynamically generated in the code behind or
classes
• All controls in this collection inherit from the
HtmlControl class
8. • Properties and Events can be managed efficiently in
the code behind
• Any server control can be referenced by its ID
property
Example:
txtTextBox.Text = “Hello!”;
9. • Code is written by the event handler that is
defined by the control
– <asp: Button On Click=“bttnGo_Click”... />
bttnGo_Click(object sender, …) { … }
• This is the key to maintaining clean, efficient
code for processing form data and UI
interaction
10. • It is good practice to prefix the name of
control ID to text that indicates its “Type”
o Textbox txtName
o Checkbox chkCorrect
o Dropdown List ddlProductTypes
o Panel pnlCustInfo
• This will make it easier when referring to
the controls at runtime in code
11. • Data
– GridView
– DataList
– SqlDataSource
– etc.
• Validation (server-side)
– RequiredFieldValidator
– RangeValidator
– RegularExpressionValidator
• Navigation
– SiteMapPath
– Menu
– TreeView
– etc.
• Login
– Login
– LoginView
– etc.
12. • Everything in VB/C# is an object, therefore
ASP. Net server controls are objects as well
• Controls can be dynamically created using
server side code (VB/C#)
13. Control Name Properties
RequiredFieldValidator
CompareValidator
RangeValidator
RegularExpressionValidator
CustomValidator
ValidationSummary
ControlToValidate, Display ,
ErrorMessage,ValidationGroup,
ControlToCompare,
MaximumValue,MinimumValue
Validation Expression
Text,ClientValidationFunction,
OnServerValidate
Header Text