Web Controls
Limitations of HTML Server Controls
2
Web Controls
Initially predicted as future of Internet application development several
years back. It is now already proven by its heavy use.
1. Rich user interface
A web control is programmed as an object, but it may
correspond to more than one tags. e.g. Calendar, GridView
2. Consistent object model
<input type=“text”> ,<input type=“password”>, <textarea> are
consolidated as a single textbox class.
.text property
3. Automatically tailored output
Browser detection
Best possible set of features
4. High level features
As compared to Html controls.
additional events, methods, properties
3
Basic Web Control Classes
4
Web Control Tags
<asp:TextBox id=“txt” runat=“server” />
<input type=“text” id=“txt” name=“ctrl” />
WebControls Namespace
– System.Web.UI.WebConrtrols
5
Web Control Hierarchy
6
WebControl Base Class
AccessKey: keyboard shortcut
BackColor, BorderColor, ForeColor:
BorderWidth: size of control border
BorderStyle: values from enum
Controls: System.Web.UI.Control, Ctype( )
Enabled: If F, control is visible, but doesn’t receive input/ focus.
EnableViewState: auto state mgt
Font: font of any text rendered in the control
Height & Width:
Page:
Parent:
TabIndex: for controlling tab order.
ToolTip: text message displayed when user hovers mouse over control.
Visible: not rendered if F.
7
Four Important Classes
1. Unit
2. Enumerations
3. Color
4. Font
8
Unit
• Unit.Pixel(20)
• Unit.Percentage(50)
• Pnl.Width=Unit.Pixel(300)
• Dim myunit as New Unit(300,UnitType.Pixel)
9
Enum
This example uses the Enum statement to define a set of named
constants.
In this case, the constants are colors you might choose to design data
entry forms for a database.
Public Enum InterfaceColors
MistyRose = &HE1E4FF&
SlateGray = &H908070&
DodgerBlue = &HFF901E&
DeepSkyBlue = &HFFBF00&
SpringGreen = &H7FFF00&
ForestGreen = &H228B22&
Goldenrod = &H20A5DA&
Firebrick = &H2222B2&
End Enum
10
Public Enum MyColors
Red=“#FF0000”
Green=“#00FF00”
Blue=“#0000FF”
End Enum
11
BorderStyle Enumeration
• Ctrl.BorderStyle=BorderStyle.Dotted
• <asp:Label BorderStyle=“Dotted” Text=“any text value” id=“ctrl”
runat=“server” />
12
Color
• Color.FromARGB(a,r,g,b)
• Color.Yellow
• ColorTranslator.FromHtml(“Blue”)
• System.Drawing namespace
• Ctrl.ForeColor=Color.FromARGB(255,255,255,255)
• Ctrl.ForeColor=Color.Red
• Ctrl.ForeColor=ColorTranslator.FromHtml(“Blue”)
13
Transparency
Alpha measures the transparency of a pixel or image.
In 32-bit uncompressed RGB video, four components define each
pixel: an alpha channel (A) and three color components (RGB).
A pixel with an alpha value of zero is completely transparent.
A pixel with an alpha value of 255 is opaque.
Between these values, the pixel has various degrees of
transparency.
14
Font
• Ctrl.Font.Bold=“True”
• Ctrl.Font.Size=FontUnit.Point(14)
15
Focus
• The Focus( ) method effects only input controls that accept
keystrokes from user.
• When the page is rendered in browser the user starts in the focused
control.
• No built in way to set focus in Html
• In .aspx
<form id=“Form1” DefaultFocus=“TextBox2” runat=“server”>
• In .vb
Dim ctrl As New TextBox
Me.Form.Controls.Add(ctrl)
ctrl.Focus()
16
Default Button
• <form id=“Form1” DefaultButton=“cmdSubmit” runat=“server”>
• The default button is the button that is clicked when the user
presses the Enter key.
• The Panel control also exposes the DefaultButton property, which
works when any input control it contains gets the focus.
17