Professional Documents
Culture Documents
Chapter 4.4 View Controls
Chapter 4.4 View Controls
Label Control
The Label Controls are used to display Text Informa on on Web Forms. User cannot Edit(change)
the Label text. Some of the proper es of Label control are enlisted below:
Text: The Text property is used to set or get the text content displayed by the Label control.
A string value can be assigned to the Text property to set the text.
ID: This property specifies a unique iden fier for the control. It is used to reference the
control in code-behind files and can be useful when working with server-side events or
accessing the control's proper es programma cally.
ForeColor: The ForeColor property is used to set the color of the text displayed by the
Label control. It accepts values such as color names, RGB values, or hexadecimal color
codes.
BackColor: The BackColor property is used to set the background color of the Label
control. It accepts values in the same format as the ForeColor property.
Font: The Font property allows to set the font proper es of the text displayed by the Label
control. It includes proper es such as FontName, FontSize, FontStyle, etc.
CssClass: The CssClass property is used to apply CSS styles to the Label control. By
assigning a CSS class to this property, you can control the appearance of the Label control
using CSS rules.
Visible: The Visible property determines whether the Label control is visible or hidden on
the web page. By default, it is set to true, but you can set it to false to hide the Label
control.
Enabled: The Enabled property determines whether the Label control is enabled or
disabled. If it is set to false, the Label control will appear grayed out and cannot be
interacted with.
Height: It is used to Specify the height of the Label Control.
Width: It is used to Specify the width of the Label Control.
BorderWidth: It is used to Sets the Border color of the Label control.
Author: Sharad Pyakurel
TextBox Control
The TextBox control is used to input the Data(text). Some of the proper es of TextBox control are
enlisted below:
Text: The Text property is used to set or get the text content displayed by the TextBox
control. A string value can be assigned to the Text property to set the text.
TextMode: It is used to set the mode of the TextBox Control as Single Mode, Mul line or
Password.
Rows: It is used to set the number of rows to display in a TextBox if the mode of the
TextBox is Mul line.
Columns: It is used to set the width of character in TextBox.
ID: This property specifies a unique iden fier for the control. It is used to reference the
control in code-behind files and can be useful when working with server-side events or
accessing the control's proper es programma cally.
ForeColor: The ForeColor property is used to set the color of the text displayed by the
TextBox control. It accepts values such as color names, RGB values, or hexadecimal color
codes.
MaxLength: It is used to set the maximum number of characters allowed in a TextBox
control.
AutoPostBack: It is used to handle the event when the TextBox control loses the focus.
BackColor: The BackColor property is used to set the background color of the TextBox
control. It accepts values in the same format as the ForeColor property.
Font: The Font property allows to set the font proper es of the text displayed by the
TextBox control. It includes proper es such as FontName, FontSize, FontStyle, etc.
CssClass: The CssClass property is used to apply CSS styles to the TextBox control. By
assigning a CSS class to this property, you can control the appearance of the TextBox
control using CSS rules.
Visible: The Visible property determines whether the TextBox control is visible or hidden
on the web page. By default, it is set to true, but you can set it to false to hide the TextBox
control.
Author: Sharad Pyakurel
Enabled: The Enabled property determines whether the TextBox control is enabled or
disabled. If it is set to false, the TextBox control will appear grayed out and cannot be
interacted with.
Readonly: It is used to read the contents by the end used but cannot change it.
Height: It is used to Specify the height of the Label Control.
Width: It is used to Specify the width of the Label Control.
Bu on Control
The Bu on control is used to create an Event and send requests to the web server. Some of the
proper es of Bu on control are enlisted below:
Text: The Text property is used to set or get the text content displayed by the Bu on
control. A string value can be assigned to the Text property to set the text.
ID: This property specifies a unique iden fier for the control. It is used to reference the
control in code-behind files and can be useful when working with server-side events or
accessing the control's proper es programma cally.
ForeColor: The ForeColor property is used to set the color of the text displayed by the
Bu on control. It accepts values such as color names, RGB values, or hexadecimal color
codes.
BackColor: The BackColor property is used to set the background color of the Bu on
control. It accepts values in the same format as the ForeColor property.
Font: The Font property allows to set the font proper es of the text displayed by the
Bu on control. It includes proper es such as FontName, FontSize, FontStyle, etc.
CssClass: The CssClass property is used to apply CSS styles to the Bu on control. By
assigning a CSS class to this property, you can control the appearance of the Bu on
control using CSS rules.
Visible: The Visible property determines whether the Bu on control is visible or hidden
on the web page. By default, it is set to true, but you can set it to false to hide the Bu on
control.
Enabled: The Enabled property determines whether the Bu on control is enabled or
disabled. If it is set to false, the Bu on control will appear grayed out and cannot be
interacted with.
Readonly: It is used to read the contents by the end used but cannot change it.
Author: Sharad Pyakurel
Command: It is also an Event that occurs when the Bu on is clicked. It is used whenever we are
using mul ple Bu on on one page. The "command" property allows us to handle different
commands in a single event handler method.
- We can access the command name and command argument using the
CommandEventArgs parameter (e) inside the btnSave_Command method. We can then
check the command name using e.CommandName and retrieve the command argument
using e.CommandArgument.
- We can have mul ple bu ons on a WebForm, each with different CommandName and
CommandArgument values. By checking the CommandName in the event handler
method, we can perform different ac ons based on the specific bu on that was clicked.
Literal Control:
Literal control allows us to display sta c text or HTML markup on a web page. Literal controls are
server-side controls, meaning they can be accessed and modified from server-side code. Literal
control is like Label control. We can show some HTML code and java script code using Literal
control.
Mode: It is a property of Literal control. The available modes are PassThrough, Encode, and
Transform. The default mode is PassThrough, which means the text is rendered as-is. Encode
mode HTML-encodes the text, and Transform mode applies any registered transforma ons to the
text.
Text: It is used to set the cap on displayed in Literal control. To access and modify the literal
control from server-side code, you can use the FindControl method to locate the control by its ID
and then manipulate its proper es.
Author: Sharad Pyakurel
PlaceHolder Control:
PlaceHolder is known as container control in Asp.Net. It is mainly used to store the value of other
controls. You can use Controls.Add() method to Add controls to a PlaceHolder. The Placeholder
control is used to define a container or a placeholder for other controls. It is a non-visual control
that allows us to dynamically add or remove controls at run me. Placeholder control is primarily
used for crea ng dynamic user interfaces or for condi onally rendering controls based on certain
condi ons.
- The ID a ribute is set to "myPlaceholder" to give the control a unique iden fier.
- We can add controls dynamically to the Placeholder control at run me using server-side
code as follows.
myPlaceholder.Controls.Add(btnEnquery);
}
DropDownList Control
The DropDownList control is a web server element that creates the drop-down menu and allows
users select a single item from various op ons. It can contain any number of items.
- The items of Dropdown List can be populated dynamically from code behind. We can bind
a data source to the control and set its DataTextField and DataValueField proper es to
specify the display text and values for the items.
- Events such as selec on changes can be handled by adding event handlers in the code-
behind file. For example, to handle the SelectedIndexChanged event.
CheckBox
The CheckBox control allows users to select or deselect an op on.
- Here we have added the OnCheckedChanged a ribute to specify the event handler
method, CheckBox1_CheckedChanged. We also have set the AutoPostBack a ribute to
"true" to trigger a postback when the checkbox state changes.
RadioBu on
The RadioBu on control is used to present a list of op ons where the user can select a single
op on from the list. Only one RadioBu on within a group can be selected at a me.
- RadioBu on controls with the same GroupName a ribute will create a group of op ons.
The GroupName a ribute ensures that only one RadioBu on can be selected within the
group.
- The Page_Load event handler is used to subscribe to the CheckedChanged event of each
RadioBu on control. The RadioBu on_CheckedChanged event handler is called when the
selec on changes.