Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 40

Button Controls

ASP.NET provides three types of button control:


 Button : It displays text within a rectangular area.
 Link Button : It displays text that looks like a hyperlink.
 Image Button : It displays an image.
When a user clicks a button, two events are raised: Click and Command.
Basic syntax of button control:
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Click" / >

Common properties of the button control:

Property Description

Text The text displayed on the button. This is for button and link button
controls only.

ImageUrl For image button control only. The image to be displayed for the button.

AlternateText For image button control only. The text to be displayed if the browser
cannot display the image.

CausesValidation Determines whether page validation occurs when a user clicks the
button. The default is true.

CommandName A string value that is passed to the command event when a user clicks
the button.

CommandArgument A string value that is passed to the command event when a user clicks
the button.

PostBackUrl The URL of the page that is requested when the user clicks the button.
Text Boxes and Labels
Text box controls are typically used to accept input from the user. A text box control
can accept one or more lines of text depending upon the settings of the TextMode
attribute.
Label controls provide an easy way to display text which can be changed from one
execution of a page to the next. If you want to display text that does not change,
you use the literal text.
Basic syntax of text control:
<asp:TextBox ID="txtstate" runat="server" ></asp:TextBox>

Common Properties of the Text Box and Labels:

Property Description

TextMode Specifies the type of text box. SingleLine creates a standard text box,
MultiLIne creates a text box that accepts more than one line of text and
the Password causes the characters that are entered to be masked. The
default is SingleLine.

Text The text content of the text box.

MaxLength The maximum number of characters that can be entered into the text
box.

Wrap It determines whether or not text wraps automatically for multi-line text
box; default is true.

ReadOnly Determines whether the user can change the text in the box; default is
false, i.e., the user can not change the text.

Columns The width of the text box in characters. The actual width is determined
based on the font that is used for the text entry.

Rows The height of a multi-line text box in lines. The default value is 0,
means a single line text box.

The mostly used attribute for a label control is 'Text', which implies the text
displayed on the label.
Check Boxes and Radio Buttons
A check box displays a single option that the user can either check or uncheck and
radio buttons present a group of options from which the user can select just one
option.
To create a group of radio buttons, you specify the same name for the GroupName
attribute of each radio button in the group. If more than one group is required in a
single form, then specify a different group name for each group.
If you want check box or radio button to be selected when the form is initially
displayed, set its Checked attribute to true. If the Checked attribute is set to true for
multiple radio buttons in a group, then only the last one is considered as true.
Basic syntax of check box:
<asp:CheckBox ID= "chkoption" runat= "Server">
</asp:CheckBox>

Basic syntax of radio button:


<asp:RadioButton ID= "rdboption" runat= "Server">
</asp: RadioButton>

Common properties of check boxes and radio buttons:

Property Description

Text The text displayed next to the check box or radio button.

Checked Specifies whether it is selected or not, default is false.

GroupName Name of the group the control belongs to.

List Controls
ASP.NET provides the following controls

 Drop-down list,
 List box,
 Radio button list,
 Check box list,
 Bulleted list.
These control let a user choose from one or more items from the list. List boxes and
drop-down lists contain one or more list items. These lists can be loaded either by
code or by the ListItemCollection editor.
Basic syntax of list box control:
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
</asp:ListBox>

Basic syntax of drop-down list control:


<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>

Common properties of list box and drop-down Lists:

Property Description

Items The collection of ListItem objects that represents the items in the
control. This property returns an object of type ListItemCollection.

Rows Specifies the number of items displayed in the box. If actual list
contains more rows than displayed then a scroll bar is added.

SelectedIndex The index of the currently selected item. If more than one item is
selected, then the index of the first selected item. If no item is selected,
the value of this property is -1.

The value of the currently selected item. If more than one item is
selected, then the value of the first selected item. If no item is selected,
the value of this property is an empty string ("").

SelectedValue

SelectionMode Indicates whether a list box allows single selections or multiple


selections.

Common properties of each list item objects:

Property Description

Text The text displayed for the item.

Selected Indicates whether the item is selected.


Value A string value associated with the item.

It is important to notes that:


 To work with the items in a drop-down list or list box, you use the Items
property of the control. This property returns a ListItemCollection object
which contains all the items of the list.
 The SelectedIndexChanged event is raised when the user selects a different
item from a drop-down list or list box.

The ListItemCollection
The ListItemCollection object is a collection of ListItem objects. Each ListItem object
represents one item in the list. Items in a ListItemCollection are numbered from 0.
When the items into a list box are loaded using strings like:
lstcolor.Items.Add("Blue"), then both the Text and Value properties of the list item
are set to the string value you specify. To set it differently you must create a list item
object and then add that item to the collection.
The ListItemCollection Editor is used to add item to a drop-down list or list box. This
is used to create a static list of items. To display the collection editor, select edit
item from the smart tag menu, or select the control and then click the ellipsis button
from the Item property in the properties window.
Common properties of ListItemCollection:

Property Description

Item(integer) A ListItem object that represents the item at the specified index.

Count The number of items in the collection.

Common methods of ListItemCollection:

Methods Description

Add(string) Adds a new item at the end of the collection and assigns the string
parameter to the Text property of the item.

Add(ListItem) Adds a new item at the end of the collection.


Insert(integer, string) Inserts an item at the specified index location in the collection, and
assigns string parameter to the text property of the item.

Insert(integer, ListItem) Inserts the item at the specified index location in the collection.

Remove(string) Removes the item with the text value same as the string.

Remove(ListItem) Removes the specified item.

RemoveAt(integer) Removes the item at the specified index as the integer.

Clear Removes all the items of the collection.

FindByValue(string) Returns the item whose value is same as the string.

FindByValue(Text) Returns the item whose text is same as the string.

Radio Button list and Check Box list


A radio button list presents a list of mutually exclusive options. A check box list
presents a list of independent options. These controls contain a collection of
ListItem objects that could be referred to through the Items property of the control.
Basic syntax of radio button list:
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
AutoPostBack="True"

OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
</asp:RadioButtonList>

Basic syntax of check box list:


<asp:CheckBoxList ID="CheckBoxList1" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
</asp:CheckBoxList>

Common properties of check box and radio button lists:


Property Description

RepeatLayout This attribute specifies whether the table tags or the normal html flow to
use while formatting the list when it is rendered. The default is Table.

RepeatDirection It specifies the direction in which the controls to be repeated. The values
available are Horizontal and Vertical. Default is Vertical.

RepeatColumns It specifies the number of columns to use when repeating the controls;
default is 0.

Bulleted lists and Numbered lists


The bulleted list control creates bulleted lists or numbered lists. These controls
contain a collection of ListItem objects that could be referred to through the Items
property of the control.
Basic syntax of a bulleted list:
<asp:BulletedList ID="BulletedList1" runat="server">
</asp:BulletedList>

Common properties of the bulleted list:

Property Description

BulletStyle This property specifies the style and looks of the bullets, or numbers.

RepeatDirection It specifies the direction in which the controls to be repeated. The values
available are Horizontal and Vertical. Default is Vertical.

RepeatColumns It specifies the number of columns to use when repeating the controls;
default is 0.

HyperLink Control
The HyperLink control is like the HTML <a> element.
Basic syntax for a hyperlink control:
<asp:HyperLink ID="HyperLink1" runat="server">
HyperLink
</asp:HyperLink>

It has the following important properties:

Property Description

ImageUrl Path of the image to be displayed by the control.

NavigateUrl Target link URL.

Text The text to be displayed as the link.

Target The window or frame which loads the linked page.

Image Control
The image control is used for displaying images on the web page, or some
alternative text, if the image is not available.
Basic syntax for an image control:
<asp:Image ID="Image1" runat="server">

It has the following important properties:

Property Description

AlternateText Alternate text to be displayed in absence of the image.

ImageAlign Alignment options for the control.

ImageUrl Path of the image to be displayed by the control.


Using the Standard Controls in ASP.NET
Common Server Control

Label control
Label control and the Literal control are used to display text in a page. Literal
control only supports text property, but the Label control has a number of
formatting properties.
By default, a Label control renders its content in an HTML <span> tag. After
executing your application, you can see the respective label <span> tag by
using view source on the browser.

The Label control displays text at a particular position on a Web page.


Generally Label control is used as the caption of a TextBox.

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

Literal control
It is light weight control. The Literal Control is similar to the Label Control but
it does not support properties like BackColor, ForeColor, BorderColor,
BorderStyle, BorderWidth, etc. Also you cannot apply a style to a literal
control. It is used to display static text on a Web page without adding
additional properties or HTML tags.

<asp:Literal ID="Literal1" runat="server">It is a Literal


Control</asp:Literal>

TextBox control
The TextBox control is frequently used and one of the most important
control. It is used to collect information from a user. It is an input control
which is used to input the data.

The TextBox control contains an important property called TextMode. By


using this property you can set textbox as

 SingleLine
 MultiLine
 Password
SingleLine mode is default mode of textbox control and allows the user to
enter data in a single line of text.

Password mode masks (text is hidden) the values entered by the user.

MultiLine mode enables user to enter text in more than one line. You can
use MultiLine mode, in combination with the Columns and Rows properties.
Column specifies the number of columns (Width) and rows specify the
number of rows (Height) to display.

Another important property of textbox control is MaxLength. It sets the limit


on the number of character that a user can enter into textbox.

TextBox control supports the following event:

TextChanged: It fires, when you change the content or text of the textbox
control. TextChanged event only fire, when AutoPostBack property has the
value True. By default AutoPostBack property has the value false.

If you change the text of the TextBox control and press tab key from the
keyboard, the form is automatically posted back to the server.

Button Controls
There are three types of button control available in ASP.NET:

 Button
 Link Button
 Image Button
Button control

Button control postbacks the web page to webserver, when user clicks the
button. A Button control can be used as a submit button (default) or a
command button.
You can also use Button control as a command button. It is useful when you
want to group a set of buttons. Button control has property called
CommandName. Assign unique CommandName value for each button.
Create a single command event handler explicitly, that will handle the event
of all command buttons.

Suppose that you have four buttons as given below and want to create all
buttons as a command button.

Provide a unique CommandName to each button. As example First, Last,


Previous, Next.

Example: Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Button ID="Button1" runat="server"
OnCommand="Navigate_Command" Text="<<" CommandName="First"
Width="65px"/>
<asp:Button ID="Button2" runat="server"
OnCommand="Navigate_Command" Text="<" CommandName="Previous"
Width="65px"/>
<asp:Button ID="Button3" runat="server"
OnCommand="Navigate_Command" Text=">" CommandName="Next"
Width="65px"/>
<asp:Button ID="Button4" runat="server"
OnCommand="Navigate_Command" Text=">>" CommandName="Last"
Width="65px"/>
</form>
</body>
</html>

Default.aspx.cs

using System;
using System.Web.UI.WebControls;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Navigate_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "First":
Response.Write("First");
break;
case "Previous":
Response.Write("Previous");
break;
case "Next":
Response.Write("Next");
break;
case "Last":
Response.Write("Last");
break;
}
}
}

CausesValidation property: It checks the page validation. By default this


property is true for button control. If you set CauseValidation value to false,
then it will bypass the page validation.

LinkButton

LinkButton control displays a link instead of a push button. By default, a


LinkButton control is a Submit button.

Some of the important properties of LinkButton Control are:

CausesValidation: If this property is set as true then validation will be


performed when Linkbutton is be clicked. Otherwise it will bypass the
validation.

PostBackUrl: It posts a form to a particular page when the LinkButton


control is clicked.

ValidationGroup: The group of controls when the LinkButton control causes


posts back to the server.

OnClick: Attach a server side method that will fire when this button will be
clicked.

OnClientClick: You can attach a client-side script that executes when the
LinkButton is clicked.

ImageButton

The ImageButton control is similar to Button and LinkButton controls but it


always displays an image. It works as a clickable image. Most of the
properties are same as Button or LinkButton.
The main difference is ImageUrl and AlternateText property. ImageUrl Gets
or Sets the location of the image. AlternateText property provides alternate
text for the image.

Let us take an example that will show the use of TextBox and Different type
of Button.

Example: Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"


CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1
{
width: 103px;
}
.auto-style3
{
width: 165px;
}
.auto-style4
{
width: 143px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table style="width: 76%;">
<tr>
<td class="auto-style1">
<asp:Label ID="Label1" runat="server"
Text="Label">EmployeeName</asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="Label2" runat="server"
Text="Label">Password</asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password">
</asp:TextBox>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="Label3" runat="server"
Text="Label">Address</asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox3" runat="server" Height="54px"
TextMode="MultiLine" Width="211px"></asp:TextBox>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style1">
<asp:Button ID="Button1" runat="server" Text="Button" />
</td>
<td class="auto-style4">
<asp:LinkButton ID="LinkButton1"
runat="server">Submit</asp:LinkButton>
</td>
<td class="auto-style3">
<asp:ImageButton ID="ImageButton1" runat="server"
AlternateText="This is Image Button" ImageUrl="~/logo.gif"
BorderColor="Blue" BorderStyle="Solid" BorderWidth="2px"
PostBackUrl="~/Default2.aspx" />
</td>
</tr>
</table>
</form>
</body>
</html>

CheckBox Control
A CheckBox control is used to select a single or multiple options from the
available choices. For example a person can select more than one cities for
travelling.

Important Properties of the CheckBox Control

Checked: It is used to check if the check box is checked or not. This is a


boolean property.

Text: It is used to get or set the text associated with the check box control.
This is a string property.

TextAlign: It enables you to set the text right or left of the check box. By
default TextAlign property is set to right.

AutoPostBack: If you want that when you change the status of checkbox
(check or uncheck), then set AutoPostBack property true. By default this
property is set to false.

Methods:
Focus(): It sets the input focus, to a specific checkbox. Call this method for
that check box control.

Events:
CheckedChanged: This event is fired when the checked status of the
checkbox control is changed. AutoPostBack property should be set as true to
fire this event.

RadioButton Control
Radio Button control is used, when you want to select only one option from
the available choices. RadioButton control works in a group. There may be
more than one group of radio button. You can select only one RadioButton
control from particular radio button group.
Most of the properties and events are same as CheckBox control but
GroupName property is different.

When you use RadioButton, they are not in a group. You can select more
than one RadioButton, they are not mutually exclusive. You have to form the
group of radio button as above given example. You can create group by
assigning similar GroupName to RadioButton.

Let us take one example and we will use all the controls that we have
discussed till now.

In this example, when user fill all the details and click on submit button, the
information will came in last multiline textbox. When user clicks on cancel
button, all fields will be empty.

Example

using System;
public partial class EmployeeForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string Name ="Name: "+ txtName.Text;
string Email ="Email: "+ txtEmailID.Text;
string Gender="" ;
if(RDBmale.Checked)
{
Gender ="Gender: "+ RDBmale.Text;
}
if (RDBfemale.Checked)
{
Gender = "Gender: " + RDBfemale.Text;
}
string Cities = "";
if(chbAgra.Checked)
{
Cities +=chbAgra.Text+"\n";
}
if (chbDelhi.Checked)
{
Cities += chbDelhi.Text + "\n";
}
if (chbPune.Checked)
{
Cities += chbPune.Text + "\n";
}
string Address ="Address:"+ txtAddress.Text;
txtResult.Text = Name + "\n" + Email+"\n"+Gender+"\n"+"City:
"+Cities +"\n" +Address;
}
protected void btnCancel_Click(object sender, EventArgs e)
{
txtName.Text = String.Empty;
txtPassword.Text = String.Empty;
txtAddress.Text = String.Empty;
txtEmailID.Text = String.Empty;
RDBfemale.Checked = false;
RDBmale.Checked = false;
chbPune.Checked = false;
chbAgra.Checked = false;
chbDelhi.Checked = false;
txtResult.Text= String.Empty;
}
}

Output:
Field Control ID

Name TextBox txtName

Password TextBox txtPassword

Email TextBox txtEmailID

Gender RadioButton RDBmale

Prefered Cities CheckBox chbDelhi

Current Address Multiline TextBox txtAddress

Submit Button btnSubmit

Cancel Button btnCancel


Programmer's
School Search this site
Home
ASP.NET Tutorial
OOPS Concepts
SQL Tutorial
Interview Questions
https://sites.google.com/site/
httpwwwjigsblogspotin/asp-net-
standard-controls

ASP.NET Standard Controls


ASP.NET Label Control:
The Label control is used to display text on a page. The text is programmable. This control lets you app
Label control supports several properties you can use to format the text displayed by the Label: -

 BackColor: Enables you to change the background color of the label.

 BorderColor: Enables you to set the color of a border rendered around the label.

 BorderStyle: Enables you to display a border around the label. Possible values are NotSet, N
Double, Groove, Ridge, Inset, and Outset.

 BorderWidth: Enables you to set the size of a border rendered around the label.

 CssClass: Enables you to associate a Cascading Style Sheet class with the label.

 Font: Enables you to set the label’s font properties.


 ForeColor: Enables you to set the color of the content rendered by the label.

 Style: Enables you to assign style attributes to the label.

 ToolTip: Enables you to set a label’s title attribute. (In Microsoft Internet Explorer, the title attr
tooltip.)

Example: -
<html>
<script runat="server">
void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = ("Welcome, " + TextBox1.Text);
}
</script>
<head runat="server">
<title>Basic ASP.NET Web Page</title>
</head>
<body>
<form id="form1" runat="server">
<h1>Welcome to ASP.NET</h1>
<p>Type your name and click the button.</p>
<p>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server"
Text="Click" OnClick="Button1_Click" />
</p>
<p>
<asp:Label ID="Label1" runat="server"></asp:Label>
</p>
</form>
</body>
</html>
ASP.NET Literal Control:
The Literal control is similar to the Label control. You can use the Literal control to display text or H
However, unlike the Label control, the Literal control does not render its content in

The Literal control does support one property not supported by the Label control: the Mode property. The
to encode HTML content and accepts any of the following three values: -

 PassThrough: Displays the contents of the control without encoding.

 Encode: Displays the contents of the control after HTML encoding the content.

 Transform: Displays the contents of the control after stripping markup not support- ed by the reque

Example: -
<html>
<head>
<title>Literal Example</title>
<script runat="server">
void ButtonClick(Object sender, EventArgs e)
{
Literal1.Text="Welcome to ASP.NET!!";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Literal Example</h3>
<asp:Literal id="Literal1"
Text="Hello World!!"
Mode=”PassThrough”
runat="server"/>
<br /><br />
<asp:Button id="Button1"
Text="Change Literal Text"
OnClick="ButtonClick"
runat="server"/>
</form>
</body>
</html>
ASP.NET TextBox Control:
The TextBox control is used to create a text box where the us

Text box controls are typically used to accept input from the user. A text box control can accept one or m
upon the setting of the TextMode attribute. The TextMode property accepts the following three values:
 SingleLine: Displays a single-line input field.

 MultiLine: Displays a multiline input field.

 Password: Displays a single-line input field in which the text is hidden.

The TextBox control also supports the following method and event:

 Focus: Enables you to set the initial form focus to the text box.

 TextChanged Raised on the server when the contents of the text box are changed.

Example: -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
private TextBox textBox1;
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.AcceptsReturn = true;
this.textBox1.AcceptsTab = true;
this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBox1.Multiline = true;
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
//
// Form1
//
this.ClientSize = new System.Drawing.Size(284, 264);
this.Controls.Add(this.textBox1);
this.Text = "TextBox Example";
this.ResumeLayout(false);
this.PerformLayout();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
ASP.NET CheckBox Control:
The CheckBox control is used to display a
A check box displays a single option that the user can either check or uncheck and radio buttons pres
which the user can select just
The CheckBox control supports the following properties, method and event:

 AccessKey: Enables you to specify a key that navigates to the TextBox control.

 AutoPostBack: Enables you to post the form containing the CheckBox back to the server automa
checked or unchecked.

 Checked: Enables you to get or set whether the CheckBox is checked.

 Enabled: Enables you to disable the TextBox.


 TabIndex: Enables you to specify the tab order of the check box.

 Text: Enables you to provide a label for the check box.

 TextAlign: Enables you to align the label for the check box. Possible values are Left and Right.

 Focus: Enables you to set the initial form focus to the check box.

 CheckedChanged: Raised on the server when the check box is checked or unchecked.

Example: -
private void HandleCheck(object sender, RoutedEventArgs e)
{
text1.Text = "The CheckBox is checked.";
}
private void HandleUnchecked(object sender, RoutedEventArgs e)
{
text1.Text = "The CheckBox is unchecked.";
}
private void HandleThirdState(object sender, RoutedEventArgs e)
{
text1.Text = "The CheckBox is in the indeterminate state.";
}
ASP.NET RadioButton Control:
The RadioButton control is used to display a radio button. To create a set of radio buttons using data bind
control!
To create a group of radio buttons, you specify the same name for the GroupName attribute of each radio
than one group is required in a single form specify a different group n
The RadioButton control supports the following properties, method and event:
 AccessKey: Enables you to specify a key that navigates to the RadioButton control.

 AutoPostBack: Enables you to post the form containing the RadioButton back to the server a
button is checked or unchecked.

 Checked: Enables you to get or set whether the RadioButton control is checked.

 Enabled: Enables you to disable the RadioButton.

 GroupName: Enables you to group RadioButton controls.

 TabIndex: Enables you to specify the tab order of the RadioButton control.

 Text: Enables you to label the RadioButton control.

 TextAlign: Enables you to align the RadioButton label. Possible values are Left and Right.

 Focus: Enables you to set the initial form focus to the RadioButton control.
 CheckedChanged: Raised on the server when the RadioButton is checked or unchecked.

Example: -
<html>
<body>
<form runat="server">
Select your favorite color:
<br>
<asp:RadioButton id="red" Text="Red" Checked="True"
GroupName="colors" runat="server"/>
<br>
<asp:RadioButton id="green" Text="Green"
GroupName="colors" runat="server"/>
<br>
<asp:RadioButton id="blue" Text="Blue"
GroupName="colors" runat="server"/>
<br>
<asp:Button text="Submit" OnClick="submit" runat="server"/>
<p><asp:Label id="Label1" runat="server"/></p>
</form>
</body>
</html>
ASP.NET Button Control:
The Button control is used to display a push button. The push button may be a submit button or a comm
control is a submit
A command button has a command name and allows you to create multiple Button controls on a page. It
handler to control the actions performed when the command
A submit button does not have a command name and it posts the page back to the server when it is click
event handler to control the actions performed when the submit
The Button control supports the following properties, method and event:

 AccessKey: Enables you to specify a key that navigates to the Button control.

 CommandArgument: Enables you to specify a command argument passed to the Command even

 CommandName: Enables you to specify a command name passed to the Command event.
 Enabled: Enables you to disable the Button control.

 OnClientClick: Enables you to specify a client-side script that executes when the button is clicked

 PostBackUrl: Enables you to post a form to a particular page.

 TabIndex: Enables you to specify the tab order of the Button control.

 Text: Enables you to label the Button control.

 UseSubmitBehavior: Enables you to use JavaScript to post a form.

 Focus: Enables you to set the initial form focus to the Button control.

 Click: Raised when the Button control is clicked.

 Command: Raised when the Button control is clicked. The CommandName and CommandArgume

Example: -
<html>
<body>
<form runat="server">
Enter your name:
<asp:TextBox id="txt1" runat="server" />
<asp:Button OnClick="submit" Text="Submit" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
ASP.NET LinkButton Control:
The LinkButton control is used to create a hyperlink button. This control looks like a HyperLink control bu
as the Button
The CheckBox control supports the following properties, method and event:

 AccessKey: Enables you to specify a key that navigates to the Button control.

 CommandArgument: Enables you to specify a command argument passed to the Command even

 CommandName: Enables you to specify a command name passed to the Command event.

 Enabled: Enables you to disable the LinkButton control.

 OnClientClick: Enables you to specify a client-side script that executes when the LinkButton is clic

 PostBackUrl: Enables you to post a form to a particular page.

 TabIndex: Enables you to specify the tab order of the LinkButton control.
 Text: Enables you to label the LinkButton control.

 Focus: Enables you to set the initial form focus to the LinkButton control

 Click: Raised when the LinkButton control is clicked.

 Command: Raised when the LinkButton control is clicked. The CommandName and CommandA
event.

Example: -
<html>
<head>
<title>LinkButton Example</title>
<script language="C#" runat="server">
void LinkButton_Click(Object sender, EventArgs e)
{
Label1.Text="You clicked the link button";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>LinkButton Example</h3>
<asp:LinkButton id="LinkButton1"
Text="Click Me"
Font-Names="Verdana"
Font-Size="14pt"
OnClick="LinkButton_Click"
runat="server"/>
<br />
<asp:Label id="Label1" runat="server" />
</form>
</body>
</html>
ASP.NET ImageButton Control:
The ImageButton control is used to display a clickable image.The ImageButton control, like the Butt
enables you to post a form to
The ImageButton control supports the following properties, method and event:

 AccessKey: Enables you to specify a key that navigates to the ImageButton control.

 AlternateText: Enables you to provide alternate text for the image (required for accessibility).

 DescriptionUrl: Enables you to provide a link to a page that contains a detailed description of th
complex image accessible).

 CommandArgument: Enables you to specify a command argument that is passed to the Comman

 CommandName: Enables you to specify a command name passed to the Command event.

 Enabled: Enables you to disable the ImageButton control.

 GenerateEmptyAlternateText: Enables you to set the AlternateText property to an empty string.

 ImageAlign: Enables you to align the image relative to other HTML elements in the page. Pos
AbsMiddle, Baseline, Bottom, Left, Middle, NotSet, Right, TextTop, and Top.
 ImageUrl: Enables you to specify the URL to the image.

 OnClientClick: Enables you to specify a client-side script that executes when the ImageButton is c

 PostBackUrl: Enables you to post a form to a particular page.

 TabIndex: Enables you to specify the tab order of the ImageButton control.

 Focus: Enables you to set the initial form focus to the ImageButton control.

 Click: Raised when the ImageButton control is clicked.

 Command: Raised when the ImageButton control is clicked. The CommandName and Command
event.

Example: -
<html>
<head>
<title>ImageButton Sample</title>
<script language="C#" runat="server">
void ImageButton_Click(object sender, ImageClickEventArgs e)
{
Label1.Text = "You clicked the ImageButton control at the coordinates: (" +
e.X.ToString() + ", " + e.Y.ToString() + ")";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageButton Sample</h3>
Click anywhere on the image.<br /><br />
<asp:ImageButton id="imagebutton1" runat="server"
AlternateText="ImageButton 1"
ImageAlign="left"
ImageUrl="images/pict.jpg"
OnClick="ImageButton_Click"/>
<br /><br />
<asp:label id="Label1" runat="server"/>
</form>
</body>
</html>
ASP.NET Image Control:
The image control is used for displaying images on the web page, or some alternative text, if the image
control is used to display
The Image control supports the following properties:

 AlternateText: Enables you to provide alternate text for the image (required for accessibility).

 DescriptionUrl: Enables you to provide a link to a page that contains a detailed description of th
complex image accessible).

 GenerateEmptyAlternateText: Enables you to set the AlternateText property to an empty string.

 ImageAlign: Enables you to align the image relative to other HTML elements in the page. Pos
AbsMiddle, Baseline, Bottom, Left, Middle, NotSet, Right, TextTop, and Top.

 ImageUrl: Enables you to specify the URL to the image.

Example: -
<script runat=”server”>
void Page_Load()
{
Random rnd = new Random();
switch (rnd.Next(3))
{
case 0:
imgRandom.ImageUrl = “Picture1.gif”;
imgRandom.AlternateText = “Picture 1”;
break;
case 1:
imgRandom.ImageUrl = “Picture2.gif”;
imgRandom.AlternateText = “Picture 2”;
break;
case 2:
imgRandom.ImageUrl = “Picture3.gif”;
imgRandom.AlternateText = “Picture 3”;
break;
}
}
</script>
<html>
<head id=”Head1” runat=”server”>
<title>Show Image</title> </head>
<body>
<form id=”form1” runat=”server”>
<div>
<asp:Image id=”imgRandom” Runat=”server” />
</div>
</form>
</body>
</html>
ASP.NET ImageMap Control:
The ASP.NET ImageMap control allows you to create an image that has individual regions that users ca
spots. Each of these hot spots can be a separate hyperlink or postback event.The ImageMap control en
side image map. An image map displays an image. When you click different areas of th
An ImageMap control is composed out of instances of the HotSpot class. A HotSpot defines the clickab
The ASP.NET Framework ships with three HotSpot classes:

 CircleHotSpot: Enables you to define a circular region in an image map.

 PolygonHotSpot: Enables you to define an irregularly shaped region in an image map.


 RectangleHotSpot: Enables you to define a rectangular region in an image map.

The ImageMap control supports the following properties, method and event:

 AccessKey: Enables you to specify a key that navigates to the ImageMap control.

 AlternateText: Enables you to provide alternate text for the image (required for accessibility).

 DescriptionUrl: Enables you to provide a link to a page that contains a detailed description of th
complex image accessible).

 GenerateEmptyAlternateText: Enables you to set the AlternateText property to an empty string.

 HotSpotMode: Enables you to specify the behavior of the image map when you click a region. P
Navigate, NotSet, and PostBack.

 HotSpots: Enables you to retrieve the collection of HotSpots contained in the ImageMap control.

 ImageAlign: Enables you to align the image map with other HTML elements in the page. Poss
AbsMiddle, Baseline, Bottom, Left, Middle, NotSet, Right, TextTop, and Top.
 ImageUrl: Enables you to specify the URL to the image.

 TabIndex: Enables you to specify the tab order of the ImageMap control.

 Target: Enables you to open a page in a new window.

 Focus: Enables you to set the initial form focus to the ImageMap control.

 Click: Raised when you click a region of the ImageMap and the HotSpotMode prop- erty is set to t

Example: -
<html>
<head id="head1" runat="server">
<title>ImageMap Class Navigate Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Navigate Example</h3>
<h4>Shopping Choices:</h4>
<asp:imagemap id="Shop"
imageurl="Images/ShopChoice.jpg"
width="150"
height="360"
alternatetext="Shopping choices"
runat="Server">
<asp:circlehotspot
navigateurl="http://www.tailspintoys.com"
x="75"
y="290"
radius="75"
hotspotmode="Navigate"
alternatetext="Shop for toys">
</asp:circlehotspot>
<asp:circlehotspot
navigateurl="http://www.cohowinery.com"
x="75"
y="120"
radius="75"
hotspotmode="Navigate"
alternatetext="Shop for wine">
</asp:circlehotspot>
</asp:imagemap>
</form>
</body>
</html>

Comments

You do not have permission to add comments.

Sign in|Recent Site Activity|Report Abuse|Print Page|Powered By Google Sites

https://www.guru99.com/asp-net-controls.html
refer this for example

https://www.javatpoint.com/asp-net-label

https://www.ankitweblogic.com/asp/standardcontrol.php

Asp.Net Standard Control


ASP.NET provides a number of controls that can be added to
Web forms pages. These controls are also known as server-side
controls or server controls. They are available in namespace
System.Web.UI.WebControls.

ASP.NET Controls are divided into seven groups:

ASP.Net Standard Controls


S.No. Web Control H
<asp:Label> <span> … </span>

<asp:TextBox> <input type="text" value="…">

<asp:Image> <img src="…">

<asp:Button> <input type="submit">

<asp:LinkButton> <a href="jscript:_doPostBack(…)"> … </a>

<asp:ImageButton> <input type="image">

<asp:HyperLink> <a href="…"> … </a>

<asp:RadioButton> <input type="radio">

<asp:CheckBox> <input type="checkbox">

<asp:DropDownList> <select> … </select>

<asp:ListBox> <select size="…"> … </select>

<asp:Panel> <div> … </div>

<asp:Table> <table> … </table>

You might also like