SlideShare a Scribd company logo
• 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
Chapter 6
Chapter 6
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" />
Chapter 6
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.
Chapter 6
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>

More Related Content

PPT
Session 3 Bai 3 ve winform
PDF
Visual Basics for Application
PPTX
Basic controls in asp
DOCX
PDF
MA3696 Lecture 9
DOC
Crosstab query techniques
ODP
SQL Tunning
Session 3 Bai 3 ve winform
Visual Basics for Application
Basic controls in asp
MA3696 Lecture 9
Crosstab query techniques
SQL Tunning

What's hot (15)

ODP
Oracle SQL Advanced
PDF
Form personalization 395117_r12_updated1212
PDF
05.Blend Expression, Transformation & Animation
PPTX
Insert Statement
PPTX
MS SQL SERVER: Time series algorithm
DOCX
Regular Expressions in QTP
PPS
Advance Excel tips
PPT
Sql2005 Xml
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPT
Excell vba
PDF
Autocad 2013-tips-and-tricks-2
PPT
AIA101.2.Access Queries Accelerated
PPTX
Ado object
PPTX
Advanced Excel, Day 1
Oracle SQL Advanced
Form personalization 395117_r12_updated1212
05.Blend Expression, Transformation & Animation
Insert Statement
MS SQL SERVER: Time series algorithm
Regular Expressions in QTP
Advance Excel tips
Sql2005 Xml
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
Excell vba
Autocad 2013-tips-and-tricks-2
AIA101.2.Access Queries Accelerated
Ado object
Advanced Excel, Day 1
Ad

Viewers also liked (12)

PPSX
Introduction of VS2012 IDE and ASP.NET Controls
PPSX
07 asp.net session10
PPTX
PPTX
Master Pages In Asp.net
PPTX
Treeview listview
PPTX
Master pages ppt
PPTX
Validation controls in asp
PPTX
Control Panel
PPTX
ASP.NET Page Life Cycle
Introduction of VS2012 IDE and ASP.NET Controls
07 asp.net session10
Master Pages In Asp.net
Treeview listview
Master pages ppt
Validation controls in asp
Control Panel
ASP.NET Page Life Cycle
Ad

Similar to Chapter 6 (20)

PPT
ASP.NET 03 - Working With Web Server Controls
PPT
ASP.NET UNIT 3.ppt
PPTX
UNIT1.pptx Introduction to ASP.NET IN IMR COLLEGE JALGOAN
PDF
C sharp and asp.net interview questions
PPTX
Asp PPT (.NET )
PPTX
Controls
DOC
The most basic inline tag
DOC
Asp.Net Page Life
PPTX
ASP DOT NET
PPT
Intro To Asp Net And Web Forms
PDF
Introductionto asp net-ppt
PPSX
03 asp.net session04
PPTX
Custom controls
PPS
03 asp.net session04
PPT
SynapseIndia creating asp controls programatically development
PPTX
Overview of ASP.Net by software outsourcing company india
PPT
Web controls
PPTX
ASP.NET 03 - Working With Web Server Controls
ASP.NET UNIT 3.ppt
UNIT1.pptx Introduction to ASP.NET IN IMR COLLEGE JALGOAN
C sharp and asp.net interview questions
Asp PPT (.NET )
Controls
The most basic inline tag
Asp.Net Page Life
ASP DOT NET
Intro To Asp Net And Web Forms
Introductionto asp net-ppt
03 asp.net session04
Custom controls
03 asp.net session04
SynapseIndia creating asp controls programatically development
Overview of ASP.Net by software outsourcing company india
Web controls

More from application developer (20)

PPTX
PPTX
PPTX
DOCX
DOCX
Next step job board (Assignment)
PPTX
PPTX
PPTX
PPTX
DOCX
Week 3 assignment
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
DOCX
C # test paper
PPTX
PPTX
Chapter 8 part2
PPTX
Chapter 8 part1
Next step job board (Assignment)
Week 3 assignment
C # test paper
Chapter 8 part2
Chapter 8 part1

Recently uploaded (20)

PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Encapsulation theory and applications.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Hybrid model detection and classification of lung cancer
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
August Patch Tuesday
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Mushroom cultivation and it's methods.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
Tartificialntelligence_presentation.pptx
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
TLE Review Electricity (Electricity).pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Encapsulation theory and applications.pdf
A comparative analysis of optical character recognition models for extracting...
Hybrid model detection and classification of lung cancer
OMC Textile Division Presentation 2021.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
August Patch Tuesday
cloud_computing_Infrastucture_as_cloud_p
Chapter 5: Probability Theory and Statistics
Enhancing emotion recognition model for a student engagement use case through...
A novel scalable deep ensemble learning framework for big data classification...
Mushroom cultivation and it's methods.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
A comparative study of natural language inference in Swahili using monolingua...
Tartificialntelligence_presentation.pptx
WOOl fibre morphology and structure.pdf for textiles
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
MIND Revenue Release Quarter 2 2025 Press Release
TLE Review Electricity (Electricity).pptx

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
  • 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" />
  • 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.
  • 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>