Professional Documents
Culture Documents
C.P. Patel & F.H. Shah Commerce College
C.P. Patel & F.H. Shah Commerce College
They are server side objects. They are programmable objects that act as user
interfaces (UI) elements on a web page. The class of these controls is
System.Web.UI.WebControls.
Syntax:
There are different types of standard controls available in ASP.NET 3.5, from that
we refer some of that as below list:
1. Label
2. TextBox
3. Button
4. CheckBox
5.RadioButton
6. Link Button
7. Image Button
8. DropDownList
1 of 16
UM06CBBI57 Server Side Web Programming Unit II
Every object, such as a web page or control, has a set of properties that describe
it. Although this set isn't identical for all objects, some properties (such as those
listed in the table below) are common to most controls. You can see every
design-time property for a given control by looking at the Properties window in
the IDE (some controls have properties that are available only at run-time).
The following table describes the properties inherited from the WebControl
class:
Property Description
AccessKey Obtains the access key that allows you to quickly
navigate to the web server control
BackColor The background color of a control
BorderColor The border color of a control
BorderStyle The border style of a control
BorderWidth The border width of a control
CssClass The CSS class applied to a control
Enabled A value indicating whether or not control is enabled
Font The font attributes for the control
EnableTheming Whether or not themes apply for a control
ForeColor The foreground color of the control
Height The height of the control
IsEnabled A value indicating whether or not control is enabled (Get
value only)
TabIndex The tab order of the control
ToolTip The text that appears when the user rests the mouse
pointer over a control
Width The width of the control
Methods are blocks of code designed into a control that tells the control how to
do things, such as set input focus to the control. Just as with properties, not all
controls have the same methods, although some common methods do exist, as
shown in the table below:
2 of 16
UM06CBBI57 Server Side Web Programming Unit II
1. Label:
Label controls are used to display text and cannot be edited by the user. They are
used to identify objects on a form — provide a description of what a certain control
will do if clicked, for example — or at run time, they can display information in
response to an event or process in your application.
You can also write code that changes the text displayed by a label control in response
to events at run time. For example, if your application takes a few minutes to process
a change, you can display a processing-status message in a label.
Properties:
Property Description
3 of 16
UM06CBBI57 Server Side Web Programming Unit II
2. Textbox: The text box control is used to display information entered by the user at
run time, or assigned to the Text property of the control at design or run time.
The TextBox control contains several properties that allow you to control the
appearance of the control. The display width of the text box, in characters, is
determined by its Columns property.
If the TextBox control is a multiline text box, the number of rows it displays is
determined by the Rows property. To display text that wraps within
theTextBox control, set the Wrap property to true.
Properties:
Property Description
AutoCompleteType Gets or sets a value that indicates the AutoComplete
behavior of the TextBox control
AutoPostBack A Boolean value that specifies whether the control is
automatically posted back to the server when the
contents change or not. Default is false
CausesValidation Gets or sets a value indicating whether validation is
4 of 16
UM06CBBI57 Server Side Web Programming Unit II
Events:
Event Means/Description
TextChanged Occurs when the user changes the text of a Textbox.
3. Button:
The Button control is used to create a button that sends a request to a web
page. The Button control post data to the server when they are cliked.
The Button control is used to display a push button. The push button may be a
submit button or a command button. By default, this control is a submit
button.
A submit button does not have a command name and it posts the Web page
back to the server when it is clicked. It is possible to write an event handler to
control the actions performed when the submit button is clicked.
A command button has a command name and allows you to create multiple
Button controls on a page. It is possible to write an event handler to control the
actions performed when the command button is clicked.
Properties:
Property Description
5 of 16
UM06CBBI57 Server Side Web Programming Unit II
Event Description
Click Occurs when the Button control is clicked.
Command Occurs when the Button control is clicked.
4. Checkbox:
The Checkbox control creates a check box that can be selected by clicking it. The
Checkbox control is displays checkmarks that allow the user to toggle between a
TRUE or FALSE condition.
Properties:
Property Description
AutoPostBack Specifies whether the form should be posted
immediately after the Checked property has changed or
not. Default is false
CausesValidation Specifies if a page is validated when a Button control is
clicked
Checked Specifies whether the check box is checked or not
InputAttributes Attribute names and values used for the Input element
for the CheckBox control
LabelAttributes Attribute names and values used for the Label element
for the CheckBox control
6 of 16
UM06CBBI57 Server Side Web Programming Unit II
Events:
Event Description
CheckedChanged Occurs when the value of the Checked property
changes between various posts to the server.
5. Radio Button:
Similar to the Checkbox control, a Radio Button control creates a Single radio
button. The RadioButton can be grouped, where only one RadioButton control can be
selected at a time. In web, forms you have to set the Radiobutton’s GroupName
property to the same value to associate them into group.
Properties:
Property Description
AutoPostBack A Boolean value that specifies whether the form
should be posted immediately after the Checked
property has changed or not. Default is false
Checked A Boolean value that specifies whether the radio
button is checked or not
Id A unique id for the control
GroupName The name of the group to which this radio
button belongs
Text The text next to the radio button
TextAlign On which side of the radio button the text should
appear (right or left)
Events:
Event Description
CheckedChanged Occurs when the value of the Checked property
changes between various posts to the server.
6. Link Button:
7 of 16
UM06CBBI57 Server Side Web Programming Unit II
The LinkButton control is used to link the current web page to some other web page,
similar to Hyper Link control. The only difference between the wto is that the
Hyperlink control just allows the browser to navigate to a new web page, whereas in
the LinkButton control, we can also perform some other action by handling the Click
and command events of this control
Properties:
Property Description
CausesValidation Specifies if a page is validated when a LinkButton
control is clicked
CommandArgument Additional information about the command to
perform
CommandName The command associated with the Command
event
PostBackUrl The URL of the page to post to from the current
page when the LinkButton control is clicked
Text The text on the LinkButton
ValidationGroup Specifies the group of controls a link button
causes validation, when it posts back to the
server
Events:
Event Description
Click Occurs when the Link Button control is clicked.
Command Occurs when the Link Button control is clicked.
7. Image Button:
8 of 16
UM06CBBI57 Server Side Web Programming Unit II
Properties:
Property Description
CausesValidation Specifies if a page is validated when an
ImageButton control is clicked
CommandArgument Additional information about the command to
perform
CommandName The command associated with the Command
event
GenerateEmptyAlternateText Specifies whether or not the control creates
an empty string as an alternate text
PostBackUrl The URL of the page to post to from the
current page when the ImageButton control is
clicked
ValidationGroup Specifies the group of controls a link button
causes validation, when it posts back to the
server
Events:
Event Description
Click Occurs when the Image Button control is clicked.
Command Occurs when the Image Button control is clicked.
8. DropDownList:
The DropDownList control displays the list of data as a drop-down list from
which you can make a single selection. You cannot select multiple items in this
control because when you make a selection from the list, the list closes automatically.
Properties:
Property Description
SelectedIndex The index of a selected item
ValidationGroup Specifies the group of controls a DropDownlist
causes validation, when it posts back to the server
Events:
Event Description
9 of 16
UM06CBBI57 Server Side Web Programming Unit II
Event Description
called. (Inherited from DataBoundControl.)
Validation
It verifies control values entered correctly and block page processing until the
control values are valid. This is very critical to application security. Validation can be
done in serve side or client side.
10 of 16
UM06CBBI57 Server Side Web Programming Unit II
CausesValidation property, which can be set to true or false. What happens when the
user clicks the button depends on the value of the CausesValidation property:
• If CausesValidation is false, ASP.NET will ignore the validation controls, the page will
be posted back, and your event-handling code will run normally.
• If CausesValidation is true (the default), ASP.NET will automatically validate the
page when the user clicks the button. It does this by performing the validation for
each control on the page. If any control fails to validate, ASP.NET will return the page
with some error information, depending on your settings. Your click event-handling
code may or may not be executed—meaning you’ll have to specifically check in the
event handler whether the page is valid.
Client-Side Validation
ASP.NET automatically adds JavaScript code for client-side validation. In this
case, when the user clicks a CausesValidation button, the same error messages will
appear without the page needing to be submitted and returned from the server. This
increases the responsiveness of your web page.
However, even if the page validates successfully on the client side, ASP.NET still
revalidates it when it’s received at the server. This is because it’s easy for an
experienced user to circumvent client-side validation. For example, a malicious user
might delete the block of
JavaScript validation code and continue working with the page. By performing
the validation at both ends, ASP.NET makes sure your application can be as
responsive as possible while also remaining secure.
Property Description
ControlToValidate Gets or sets the input control to validate.
Display Gets or sets the display behavior of the error message in a
validation control.
EnableClientScript Gets or sets a value indicating whether client-side
validation is enabled.
Enabled Gets or sets a value that indicates whether the validation
control is enabled.
ErrorMessage Gets or sets the text for the error message displayed
in a ValidationSummary control when validation fails.
ForeColor Gets or sets the color of the message displayed when
validation fails.
IsValid Gets or sets a value that indicates whether the associated
input control passes validation.
SetFocusOnError Gets or sets a value that indicates whether focus is set to
the control specified by the ControlToValidateproperty
when validation fails.
Text Gets or sets the text displayed in the validation
control when validation fails.
ValidationGroup Gets or sets the name of the validation group to which
this validation control belongs.
Property Description
Validate It performs validation on the associated input control and
updates the IsValid property.
To use this controls, you set the ErrorMessage property to the error message you
want to display, and the ControlToValidate property to the control you want to check.
This control has an Initial value property, which is set to an empty string (“”) by
default. If the data has not changed from that value when validation occurs, the
control displays its error message.
12 of 16
UM06CBBI57 Server Side Web Programming Unit II
Properties:
Property Description
InitialValue Specifies the starting value of the input control. Default
value is ""
2) RangeValidator Control:
Properties:
Property Description
MaximumValue Specifies the maximum value of the input control
MinimumValue Specifies the minimum value of the input control
Type Specifies the data type of the value to check. The types
are:
Currency
Date
Double
Integer
String
3) CompareValidator Control:
You can also compare Date-Entry value to the constant value, for that you have
to set the ValueToCompare property.
Use the Type property to specify the type of comparision to perform. Here are
the possibilities:
Operator Discription
Equal Checks if the compared value are equal.
Not Equal Checks if the compared value are not equal.
GreaterThan Checks for the greater than relationship.
GreaterThanEqual Checks for the greater than or equal relationship.
LessThan Checks for the less than relationship.
LessThanEqual Checks for the less than or equal relationship.
DataTypeCheck Compares data types between the value enteres into the
Data-Entry control being validated and the data type
specified by the Type property
Properties:
Property Description
ControlToCompare The name of the control to compare with
Operator The type of comparison to perform. The operators are:
Equal
GreaterThan
GreaterThanEqual
LessThan
LessThanEqual
NotEqual
DataTypeCheck
4) ValidationSummary control:
The Validationsummary control, which summarize the error messages from all
validators on a web page in one location. The summary can be displayed as a list, as a
bulleted list, or as a single paragraph, based on the DisplayMode property. You can
alos specify if the summary should be displayed in the web page and in a message box
by setting the ShowSummary and showMessagebox propertises, respectively.
14 of 16
UM06CBBI57 Server Side Web Programming Unit II
Properties:
Property Description
DisplayMode How to display the summary. Legal values are:
BulletList
List
SingleParagraph
Master Page
Master page is a feature in ASP.NET 3.5 that helps define the overall layout of a
web application and reuse the defined layout in all the pages derived from the master
page. A master page contains markups and controls that you can share across
different web pages of your web site. This makes your website more manageable and
also avoids the duplication of code.
A master page contain markups, controls, banners, navigation menus and other
elements that you want to include in all the pages of your website. The web pages that
inherit the properties defined in master pages are called Content Pages. The content
pages display their own properties as well as the properties inherited from master
pages.
To create a master page for a web site, identify the controls that you want
to display on all the pages and then add these controls to the master page. You then
create the ContentPlaceHolder control for the matser page to place the content of the
web pages. Whne this website is executed, then the layout of the master page and the
content in ContentPlaceHolder control are merged to display the output of the
webpage. A master page contains multiple ContentPlaceHolder.
There TWO type of master pages: Simple mater page and Nested master page.
1) Simple master page: A simple master page simplify your website design by
creating master pages and the content pages. You don’t need to create the submaster
pages. It is a page that is combined with the content page to display the combined
page. The master and content pages are combined together to generate a single page
that inherits its properties from both the pages.
Simple Content
Master Page
Page
Combined
Page
Nested
Master
Page
Combined Combined
Page 1 Page 2
16 of 16