SlideShare une entreprise Scribd logo
1  sur  21
• Benefits of Web Controls
• Basic Web Controls
• Web Control Class Properties
• Common Web Control Concepts
• List Controls
• Table Controls
• Web Control Events
• PostBack AutoPostBack
• How Postback Events Work
• The Page Life Cycle
•   Provide a rich user interface

•   Provide a consistent object model

•   Tailor their output automatically

•   Provide high-level features
ASP.NET tags have a special format. They always
begin with the prefix asp: followed by the class name.
If there is no closing tag, the tag must end with />.

<asp:TextBox ID="txt" BackColor="Yellow" Text="Hello World"
ReadOnly="True" TextMode="MultiLine" Rows="5" runat="server" />
Most web controls begin by inheriting from the WebControl base class.
This class defines the essential functionality for tasks such as data
binding and includes some basic properties that you can use with
almost any web control

Property          Description
AccessKey         Specifies the keyboard shortcut as one letter. For example,
                  if you set this to Y, the Alt+Y keyboard combination will
                  automatically change focus to this web control.
BackColor,        Sets the colors used for the background, foreground, and
ForeColor,        border of thecontrol. In most controls, the foreground color
and BorderColor   sets the text color.
BorderWidth       Specifies the size of the control border.
BorderStyle       One of the values from the BorderStyle enumeration,
                  including Dashed, Dotted, Double, Groove, Ridge, Inset,
                  Outset, Solid, and None.
Controls          Provides a collection of all the controls contained inside
                  the current control
Property           Description
Enabled            When set to false, the control will be visible, but it will not be
                   able to receive user input or focus.
EnableViewState    Set this to false to disable the automatic state management for
                   this control
Font               Specifies the font used to render any text in the control as a
                   System.Web.UI.WebControls.FontInfo object.
Height and Width   Specifies the width and height of the control. For some controls,
                   these properties will be ignored when used with older browsers.
ID                 Specifies the name that you use to interact with the control in
                   your code
Page               Provides a reference to the web page that contains this control
                   as a system.Web.UI.Page object.
Parent             Provides a reference to the control that contains this control.
TabIndex           A number that allows you to control the tab order.
ToolTip            Displays a text message above the control
Visible            When set to false, the control will be hidden.
All the properties require the Unit structure, which combines
a numeric value with a type of measurement (pixels,
percentage, and so on.

<asp:Panel Height="300px" Width="50%" ID="pnl" runat="server" />

 pnl.Height = Unit.Pixel(300);

 pnl.Width = Unit.Percentage(50);

 // Create a Unit object.
 Unit myUnit = new Unit(300, UnitType.Pixel);

 // Assign the Unit object to several controls or properties.
 pnl.Height = myUnit;
 pnl.Width = myUnit;
Enumerations are used heavily in the .NET class library to
group a set of related constants. For example, when you set
a control’s BorderStyle property, you can choose one of
several predefined values from the BorderStyle enumeration.

ctrl.BorderStyle = BorderStyle.Dashed;



<asp:Label BorderStyle="Dashed" Text="Border Test" ID="lbl"
runat="server" />
The Color property refers to a Color object from the
System.Drawing namespace. You can create color objects
in several ways:

Using an ARGB (alpha, red, green, blue) color value:
int alpha = 255, red = 0, green = 255, blue = 0;
ctrl.ForeColor = Color.FromArgb(alpha, red, green, blue);

Using a predefined .NET color name:
ctrl.ForeColor = Color.Crimson;

Using an HTML color name:
ctrl.ForeColor = ColorTranslator.FromHtml("Blue");
ctrl.Font.Name = "Verdana";
ctrl.Font.Bold = true;

You can also set the size using the FontUnit type:
// Specifies a relative size.

ctrl.Font.Size = FontUnit.Small;

// Specifies an absolute size of 14 pixels.
ctrl.Font.Size = FontUnit.Point(14);
Unlike HTML server controls, every web control provides a
Focus() method. The Focus() method affects only input
controls
<form DefaultFocus="TextBox2" runat="server">

Another way to manage focus is using access keys. For
example, if you set the AccessKey property of a TextBox
to A, pressing Alt+A focus will switch to the TextBox.

The following label gives focus to TextBox2 when the
keyboard combination Alt+2 is pressed:

<asp:Label AccessKey="2“ AssociatedControlID="TextBox2"
runat="server“ Text="TextBox2:" />
.
The default button is the button that is “clicked” when the
user presses the Enter key.

To designate a default button, you must set the
DefaultButton property with the ID of the respective
control, as shown here:


<form DefaultButton="cmdSubmit" runat="server">
The list controls include the ListBox, DropDownList,
CheckBoxList, RadioButtonList, and BulletedList.

Multiple-Select List Controls
Some list controls can allow multiple selections.
It is supported for a ListBox, provided you have set the
SelectionMode property to the enumerated value
ListSelectionMode.Multiple.

The user can then select multiple items by holding down the
Ctrl key while clicking the items in the list.

With the CheckBoxList, multiple selections are always
possible.
The Table control is built out of a hierarchy of objects.
Each Table object contains one or more TableRow objects.
In turn, each TableRow object contains one or more
TableCell objects.
Some events, such as the Click event of a button, do occur
immediately. That’s because when clicked, the button posts
back the page. However, other actions do cause events but
don’t trigger a postback.

An example is when the user changes the text in a text box
(which triggers the TextChanged event) or chooses a new item
in a list (the SelectedIndexChanged event).

You might want to respond to these events, but without a
postback your code has no way to run.
If you want to capture a change event (such as TextChanged,
CheckedChanged, or SelectedIndexChanged) immediately, you need to
set the control’s AutoPostBack property to true.
ASP.NET also adds two additional hidden input fields that are
used to pass information back to the server. This information
consists of the ID of the control that raised the event and any
additional information that might be relevant. These fields are
initially empty, as shown here:

<input type="hidden" name="__EVENTTARGET"
id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT"
id="__EVENTARGUMENT" value="" />

Also ASP.NET generates the __doPostBack() function
automatically, provided at least one control on the page uses
automatic postbacks.
The __doPostBack() function has the responsibility for setting
these values with the appropriate information about the event
and then submitting the form. The __doPostBack() function is
shown here:
<script language="text/javascript">
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
...
}
</script>

Contenu connexe

Tendances

Regular Expressions in QTP
Regular Expressions in QTPRegular Expressions in QTP
Regular Expressions in QTP
Praveen Gorantla
 
Autocad 2013-tips-and-tricks-2
Autocad 2013-tips-and-tricks-2Autocad 2013-tips-and-tricks-2
Autocad 2013-tips-and-tricks-2
Bala Chandar
 

Tendances (15)

Oracle SQL Advanced
Oracle SQL AdvancedOracle SQL Advanced
Oracle SQL Advanced
 
Form personalization 395117_r12_updated1212
Form personalization 395117_r12_updated1212Form personalization 395117_r12_updated1212
Form personalization 395117_r12_updated1212
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation
 
Insert Statement
Insert StatementInsert Statement
Insert Statement
 
CIS 282 Final Review
CIS 282 Final ReviewCIS 282 Final Review
CIS 282 Final Review
 
MS SQL SERVER: Time series algorithm
MS SQL SERVER: Time series algorithmMS SQL SERVER: Time series algorithm
MS SQL SERVER: Time series algorithm
 
Regular Expressions in QTP
Regular Expressions in QTPRegular Expressions in QTP
Regular Expressions in QTP
 
Advance Excel tips
Advance Excel tips Advance Excel tips
Advance Excel tips
 
Sql2005 Xml
Sql2005 XmlSql2005 Xml
Sql2005 Xml
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
Excell vba
Excell vbaExcell vba
Excell vba
 
Autocad 2013-tips-and-tricks-2
Autocad 2013-tips-and-tricks-2Autocad 2013-tips-and-tricks-2
Autocad 2013-tips-and-tricks-2
 
AIA101.2.Access Queries Accelerated
AIA101.2.Access Queries AcceleratedAIA101.2.Access Queries Accelerated
AIA101.2.Access Queries Accelerated
 
Ado object
Ado objectAdo object
Ado object
 
Advanced Excel, Day 1
Advanced Excel, Day 1Advanced Excel, Day 1
Advanced Excel, Day 1
 

En vedette

Master pages ppt
Master pages pptMaster pages ppt
Master pages ppt
Iblesoft
 

En vedette (12)

Master page in asp.net
Master page in asp.netMaster page in asp.net
Master page in asp.net
 
master page_in_asp.net
master page_in_asp.netmaster page_in_asp.net
master page_in_asp.net
 
Introduction of VS2012 IDE and ASP.NET Controls
Introduction of VS2012 IDE and ASP.NET ControlsIntroduction of VS2012 IDE and ASP.NET Controls
Introduction of VS2012 IDE and ASP.NET Controls
 
07 asp.net session10
07 asp.net session1007 asp.net session10
07 asp.net session10
 
Standard control in asp.net
Standard control in asp.netStandard control in asp.net
Standard control in asp.net
 
Master Pages In Asp.net
Master Pages In Asp.netMaster Pages In Asp.net
Master Pages In Asp.net
 
Master page in ASP . NET
Master page in ASP . NETMaster page in ASP . NET
Master page in ASP . NET
 
Treeview listview
Treeview listviewTreeview listview
Treeview listview
 
Master pages ppt
Master pages pptMaster pages ppt
Master pages ppt
 
Validation controls in asp
Validation controls in aspValidation controls in asp
Validation controls in asp
 
Control Panel
Control PanelControl Panel
Control Panel
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
 

Similaire à Chapter 6

Implement a Javascript application that allows the user to enter strin.docx
Implement a Javascript application that allows the user to enter strin.docxImplement a Javascript application that allows the user to enter strin.docx
Implement a Javascript application that allows the user to enter strin.docx
mckerliejonelle
 
Data controls ppt
Data controls pptData controls ppt
Data controls ppt
Iblesoft
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
Abhishek Sur
 
Windows Forms 2.0 Enhancements
Windows Forms 2.0 EnhancementsWindows Forms 2.0 Enhancements
Windows Forms 2.0 Enhancements
guestd115f
 
AdRotator and AdRepeater Control in Asp.Net for Msc CS
AdRotator and AdRepeater Control in Asp.Net for Msc CSAdRotator and AdRepeater Control in Asp.Net for Msc CS
AdRotator and AdRepeater Control in Asp.Net for Msc CS
Thanveen
 

Similaire à Chapter 6 (20)

ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server Controls
 
unit3.2 (1).pptx
unit3.2 (1).pptxunit3.2 (1).pptx
unit3.2 (1).pptx
 
Controls
ControlsControls
Controls
 
Android interface elements and controls-chapter8
Android interface elements and controls-chapter8Android interface elements and controls-chapter8
Android interface elements and controls-chapter8
 
WPF Controls
WPF ControlsWPF Controls
WPF Controls
 
Implement a Javascript application that allows the user to enter strin.docx
Implement a Javascript application that allows the user to enter strin.docxImplement a Javascript application that allows the user to enter strin.docx
Implement a Javascript application that allows the user to enter strin.docx
 
Detail view in distributed technologies
Detail view in distributed technologiesDetail view in distributed technologies
Detail view in distributed technologies
 
Data controls ppt
Data controls pptData controls ppt
Data controls ppt
 
Asp PPT (.NET )
Asp PPT (.NET )Asp PPT (.NET )
Asp PPT (.NET )
 
The most basic inline tag
The most basic inline tagThe most basic inline tag
The most basic inline tag
 
Visual Basic.pptx
Visual Basic.pptxVisual Basic.pptx
Visual Basic.pptx
 
Visual basic
Visual basicVisual basic
Visual basic
 
XAML and WPF - Dinko Jakovljević
XAML and WPF - Dinko JakovljevićXAML and WPF - Dinko Jakovljević
XAML and WPF - Dinko Jakovljević
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
 
Windows Forms 2.0 Enhancements
Windows Forms 2.0 EnhancementsWindows Forms 2.0 Enhancements
Windows Forms 2.0 Enhancements
 
Html css
Html cssHtml css
Html css
 
AdRotator and AdRepeater Control in Asp.Net for Msc CS
AdRotator and AdRepeater Control in Asp.Net for Msc CSAdRotator and AdRepeater Control in Asp.Net for Msc CS
AdRotator and AdRepeater Control in Asp.Net for Msc CS
 
Html Form Controls
Html Form ControlsHtml Form Controls
Html Form Controls
 
Qtp 92 Tutorial769
Qtp 92 Tutorial769Qtp 92 Tutorial769
Qtp 92 Tutorial769
 
Qtp 92 Tutorial769
Qtp 92 Tutorial769Qtp 92 Tutorial769
Qtp 92 Tutorial769
 

Plus de application developer (20)

Chapter 26
Chapter 26Chapter 26
Chapter 26
 
Chapter 25
Chapter 25Chapter 25
Chapter 25
 
Chapter 23
Chapter 23Chapter 23
Chapter 23
 
Assignment
AssignmentAssignment
Assignment
 
Next step job board (Assignment)
Next step job board (Assignment)Next step job board (Assignment)
Next step job board (Assignment)
 
Chapter 19
Chapter 19Chapter 19
Chapter 19
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
Week 3 assignment
Week 3 assignmentWeek 3 assignment
Week 3 assignment
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
C # test paper
C # test paperC # test paper
C # test paper
 
Chapter 9
Chapter 9Chapter 9
Chapter 9
 
Chapter 8 part2
Chapter 8   part2Chapter 8   part2
Chapter 8 part2
 
Chapter 8 part1
Chapter 8   part1Chapter 8   part1
Chapter 8 part1
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

Chapter 6

  • 1. • Benefits of Web Controls • Basic Web Controls • Web Control Class Properties • Common Web Control Concepts • List Controls • Table Controls • Web Control Events • PostBack AutoPostBack • How Postback Events Work • The Page Life Cycle
  • 2. Provide a rich user interface • Provide a consistent object model • Tailor their output automatically • Provide high-level features
  • 3.
  • 4.
  • 5. ASP.NET tags have a special format. They always begin with the prefix asp: followed by the class name. If there is no closing tag, the tag must end with />. <asp:TextBox ID="txt" BackColor="Yellow" Text="Hello World" ReadOnly="True" TextMode="MultiLine" Rows="5" runat="server" />
  • 6.
  • 7. Most web controls begin by inheriting from the WebControl base class. This class defines the essential functionality for tasks such as data binding and includes some basic properties that you can use with almost any web control Property Description AccessKey Specifies the keyboard shortcut as one letter. For example, if you set this to Y, the Alt+Y keyboard combination will automatically change focus to this web control. BackColor, Sets the colors used for the background, foreground, and ForeColor, border of thecontrol. In most controls, the foreground color and BorderColor sets the text color. BorderWidth Specifies the size of the control border. BorderStyle One of the values from the BorderStyle enumeration, including Dashed, Dotted, Double, Groove, Ridge, Inset, Outset, Solid, and None. Controls Provides a collection of all the controls contained inside the current control
  • 8. Property Description Enabled When set to false, the control will be visible, but it will not be able to receive user input or focus. EnableViewState Set this to false to disable the automatic state management for this control Font Specifies the font used to render any text in the control as a System.Web.UI.WebControls.FontInfo object. Height and Width Specifies the width and height of the control. For some controls, these properties will be ignored when used with older browsers. ID Specifies the name that you use to interact with the control in your code Page Provides a reference to the web page that contains this control as a system.Web.UI.Page object. Parent Provides a reference to the control that contains this control. TabIndex A number that allows you to control the tab order. ToolTip Displays a text message above the control Visible When set to false, the control will be hidden.
  • 9. All the properties require the Unit structure, which combines a numeric value with a type of measurement (pixels, percentage, and so on. <asp:Panel Height="300px" Width="50%" ID="pnl" runat="server" /> pnl.Height = Unit.Pixel(300); pnl.Width = Unit.Percentage(50); // Create a Unit object. Unit myUnit = new Unit(300, UnitType.Pixel); // Assign the Unit object to several controls or properties. pnl.Height = myUnit; pnl.Width = myUnit;
  • 10. Enumerations are used heavily in the .NET class library to group a set of related constants. For example, when you set a control’s BorderStyle property, you can choose one of several predefined values from the BorderStyle enumeration. ctrl.BorderStyle = BorderStyle.Dashed; <asp:Label BorderStyle="Dashed" Text="Border Test" ID="lbl" runat="server" />
  • 11. The Color property refers to a Color object from the System.Drawing namespace. You can create color objects in several ways: Using an ARGB (alpha, red, green, blue) color value: int alpha = 255, red = 0, green = 255, blue = 0; ctrl.ForeColor = Color.FromArgb(alpha, red, green, blue); Using a predefined .NET color name: ctrl.ForeColor = Color.Crimson; Using an HTML color name: ctrl.ForeColor = ColorTranslator.FromHtml("Blue");
  • 12. ctrl.Font.Name = "Verdana"; ctrl.Font.Bold = true; You can also set the size using the FontUnit type: // Specifies a relative size. ctrl.Font.Size = FontUnit.Small; // Specifies an absolute size of 14 pixels. ctrl.Font.Size = FontUnit.Point(14);
  • 13. Unlike HTML server controls, every web control provides a Focus() method. The Focus() method affects only input controls <form DefaultFocus="TextBox2" runat="server"> Another way to manage focus is using access keys. For example, if you set the AccessKey property of a TextBox to A, pressing Alt+A focus will switch to the TextBox. The following label gives focus to TextBox2 when the keyboard combination Alt+2 is pressed: <asp:Label AccessKey="2“ AssociatedControlID="TextBox2" runat="server“ Text="TextBox2:" />
  • 14. . The default button is the button that is “clicked” when the user presses the Enter key. To designate a default button, you must set the DefaultButton property with the ID of the respective control, as shown here: <form DefaultButton="cmdSubmit" runat="server">
  • 15. The list controls include the ListBox, DropDownList, CheckBoxList, RadioButtonList, and BulletedList. Multiple-Select List Controls Some list controls can allow multiple selections. It is supported for a ListBox, provided you have set the SelectionMode property to the enumerated value ListSelectionMode.Multiple. The user can then select multiple items by holding down the Ctrl key while clicking the items in the list. With the CheckBoxList, multiple selections are always possible.
  • 16. The Table control is built out of a hierarchy of objects. Each Table object contains one or more TableRow objects. In turn, each TableRow object contains one or more TableCell objects.
  • 17. Some events, such as the Click event of a button, do occur immediately. That’s because when clicked, the button posts back the page. However, other actions do cause events but don’t trigger a postback. An example is when the user changes the text in a text box (which triggers the TextChanged event) or chooses a new item in a list (the SelectedIndexChanged event). You might want to respond to these events, but without a postback your code has no way to run.
  • 18. If you want to capture a change event (such as TextChanged, CheckedChanged, or SelectedIndexChanged) immediately, you need to set the control’s AutoPostBack property to true.
  • 19.
  • 20. ASP.NET also adds two additional hidden input fields that are used to pass information back to the server. This information consists of the ID of the control that raised the event and any additional information that might be relevant. These fields are initially empty, as shown here: <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /> Also ASP.NET generates the __doPostBack() function automatically, provided at least one control on the page uses automatic postbacks.
  • 21. The __doPostBack() function has the responsibility for setting these values with the appropriate information about the event and then submitting the form. The __doPostBack() function is shown here: <script language="text/javascript"> function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } ... } </script>