Top Banner
Types of Server Controls ASP.NET Web Server Controls HTML Server Controls Creating Server Controls Dynamically
13
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Session iii(server controls)

Types of Server Controls

ASP.NET Web Server Controls

HTML Server Controls

Creating Server Controls Dynamically

Page 2: Session iii(server controls)

With ASP. Net, these are any controls that run in the server space.

o Handled by ASP. Net runtimeo Must have runt=“server” attribute within the ASP. Net web formo Always identified with the “ID” attribute (also mandatory with

ASP. Net web controls)

Properties, events, etc. can all be handled by server-side code

Page 3: Session iii(server controls)

• Label• Textbox• Button• Link• Link Button• Dropdown List• List Box• Checkbox• Radio Button• Image• File Upload• Panel

• <span />• <input type=“text” />• <input type=“submit” />• <a href=[#|page] />• <a href=[postback] />• <select />• <select [size=x] />• <input type=“checkbox” />• <input type=“radio” />• <img />• <input type=“file” />• <div />

Page 4: Session iii(server controls)

• 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()

Page 5: Session iii(server controls)

• System.Web.UI.HtmlControls– Ex: HtmlButton, HtmlTable, HtmlInputText

• These are ASP. Net HTML server controls– Rendered as:– <button />, <table />, <input type=“text” />

Page 6: Session iii(server controls)

• 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

Page 7: Session iii(server controls)

• HtmlAnchor• HtmlButton• HtmlInputButton• HtmlInputHidden• HtmlInputText• HtmlImage• HtmlSelect• HtmlTable• HtmlTextArea• HtmlGenericControl

<a /><button /><input type=“button” /><input type=“hidden” /><input type=“text” /><img /><select /><table /><text area /><span />, <body />, <h1 />,

<div />…

Page 8: Session iii(server controls)

• 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!”;

Page 9: Session iii(server controls)

• 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

Page 10: Session iii(server controls)

• It is good practice to prefix the name of control ID to text that indicates its “Type”

o Textbox txtNameo Checkbox chkCorrecto Dropdown List ddlProductTypeso Panel pnlCustInfo

• This will make it easier when referring to the controls at runtime in code

Page 11: Session iii(server controls)

• Data– GridView– DataList– SqlDataSource– etc.

• Validation (server-side)– RequiredFieldValidator– RangeValidator– RegularExpressionValidator

• Navigation– SiteMapPath– Menu– TreeView– etc.

• Login– Login– LoginView– etc.

Page 12: Session iii(server controls)

• 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#)

Page 13: Session iii(server controls)

Control Name Properties

RequiredFieldValidator

CompareValidator

RangeValidator

RegularExpressionValidator

CustomValidator

ValidationSummary

ControlToValidate, Display , ErrorMessage,ValidationGroup,ControlToCompare,

MaximumValue,MinimumValue

Validation Expression

Text,ClientValidationFunction, OnServerValidateHeader Text