2 Asp.Net Standard Controls

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Asp.

Net Standard Controls

Bulleted List:-

The BulletedList control is used to create a list of items formatted with bullets. To specify the
individual list items that you want to show in a BulletedList control, place a ListItem object for each
entry between the opening and closing tags of the BulletedList control. The control can display the list
items with many different kinds of bullet styles. The control is also actively used to show a list of hyperlinks.

The BulletedList control renders either an unordered (bulleted) or ordered (numbered) list. Each list
item can be rendered as plain text, a LinkButton control, or a link to another web page. For example, the
page given below uses the BulletedList control to render an unordered list of products.

We can control the appearance of the bullets that appear for each list item with the BulletStyle property. This
property accepts the following values:

• Circle
• CustomImage
• Disc
• LowerAlpha
• LowerRoman
• NotSet
• Numbered
• Square
• UpperAlpha
• UpperRoman
We can set BulletStyle to Numbered to display a numbered list. If you set this property to the value CustomImage and
assign an image path to the BulletImageUrl property, then we can associate an image with each list item.

RadioButton

It is an input control which is used to takes input from the user. It allows user to select a choice
from the group of choices. To create RadioButton we can drag it from the toolbox of visual studio.
This is a server side control and ASP.NET provides own tag to create it.

e.g. < asp:RadioButtonID="RadioButton1" runat="server" Text="Male" GroupName="gender"/>


Server renders it as the HTML control and produces the following code to the browser.
<input id="RadioButton1" type="radio" name="gender" value="RadioButton1" /><labelforlabelfor="Radi
oButton1">Male</label>
// WebControls.aspx
1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebControls.aspx.cs"
2. Inherits="WebFormsControlls.WebControls" %>
3. <!DOCTYPE html>
4. <html xmlns="http://www.w3.org/1999/xhtml">
5. <head runat="server">
6. <title></title>
7. </head>
8. <body>
9. <form id="form1" runat="server">
10. <div>
11. <asp:RadioButton ID="RadioButton1" runat="server" Text="Male" GroupName="gender"
/>
12. <asp:RadioButton ID="RadioButton2" runat="server" Text="Female" GroupName="gende
r" />
13. </div>
14. <p>
15. <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" style="
width: 61px" />
16. </p>
17. </form>
18. <asp:Label runat="server" id="genderId"></asp:Label>
19. </body>
20. </html>

// WebControls.aspx.cs
1. using System;
2. using System.Collections.Generic;
3. using System.Linq;
4. using System.Web;
5. using System.Web.UI;
6. using System.Web.UI.WebControls;
7. namespace WebFormsControlls
8. {
9. public partial class WebControls : System.Web.UI.Page
10. {
11. protected void Button1_Click(object sender, EventArgs e)
12. {
13. genderId.Text = "";
14. if (RadioButton1.Checked)
15. {
16. genderId.Text = "Your gender is "+RadioButton1.Text;
17. }
18. else genderId.Text = "Your gender is "+RadioButton2.Text;
19.
20. }
21. }
22. }
Radio Button List

ASP.NET Radio Button List (ASPxRadioButtonList) editor is a radio button group that allows end-users to
select a single item at a time. Its contents can be generated dynamically by binding the editor to a data
source. You can also create items explicitly by populating the Items collection manually. For each list item,
you can specify its caption and associated value.

The item selected within ASPxRadioButtonList can be determined by using specific properties declared at the
editor level (SelectedItem, SelectedIndex). You can easily get and set the selected item on the client side
using specific client methods (GetSelectedItem/SetSelectedItem, GetSelectedIndex/SetSelectedIndex).

The ASPxRadioButtonList layout can be flexibly customized. You can display radio button items in several
columns (via the RepeatColumns property), set the direction of items within the editor (horizontal or vertical,
via the RepeatDirection property), and specify whether items are aligned within a table or rendered without
any table structure (via the RepeatLayout property).

CheckBox
It is used to get multiple inputs from the user. It allows user to select choices from the set of
choices.It takes user input in yes or no format. It is useful when we want multiple choices from the
user. To create CheckBox we can drag it from the toolbox in visual studio. This is a server side
control and ASP.NET provides own tag to create it. The example is given below.
e.g. < asp:CheckBox ID="CheckBox2" runat="server" Text="J2EE"/>

// WebControls.aspx

1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebControls.aspx.cs"


2. Inherits="WebFormsControlls.WebControls" %>
3. <!DOCTYPE html>
4. <html xmlns="http://www.w3.org/1999/xhtml">
5. <head runat="server">
6. <title></title>
7. </head>
8. <body>
9. <form id="form1" runat="server">
10. <div>
11. <h2>Select Courses</h2>
12. <asp:CheckBox ID="CheckBox1" runat="server" Text="J2SE" />
13. <asp:CheckBox ID="CheckBox2" runat="server" Text="J2EE" />
14. <asp:CheckBox ID="CheckBox3" runat="server" Text="Spring" />
15. </div>
16. <p>
17. <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
18. </p>
19. </form>
20. <p>
21. Courses Selected: <asp:Label runat="server" ID="ShowCourses"></asp:Label>
22. </p>
23. </body>
24. </html>
// WebControls.aspx.cs

1. using System;
2. using System.Collections.Generic;
3. using System.Linq;
4. using System.Web;
5. using System.Web.UI;
6. using System.Web.UI.WebControls;
7. namespace WebFormsControlls
8. {
9. public partial class WebControls : System.Web.UI.Page
10. {
11. protected void Page_Load(object sender, EventArgs e)
12. {
13. ShowCourses.Text = "None";
14. }
15. protected void Button1_Click(object sender, EventArgs e)
16. {
17. var message = "" ;
18. if (CheckBox1.Checked)
19. {
20. message = CheckBox1.Text+" ";
21. }
22. if (CheckBox2.Checked)
23. {
24. message += CheckBox2.Text + " ";
25. }
26. if (CheckBox3.Checked)
27. {
28. message += CheckBox3.Text;
29. }
30. ShowCourses.Text = message;
31. }
32. }
33. }
CheckBoxList

ASP.NET CheckBoxList is a web control that can be used to collate the items that
can be checked, thus giving the user the ability to select multiple items
simultaneously. This list of items in the CheckBoxList can be dynamically
generated using the Data Binding functions.

LinkButton

It is a server web control that acts as a hyperlink. It is used to display a hyperlink-


style button control on the web page. ASP.NET provides a tag to create
LinkButton and has following syntax.

<asp:LinkButton

AccessKey="string"

ID="string"

OnClick="Click event handler"

OnClientClick="string"

OnCommand="Command event handler"

OnDataBinding="DataBinding event handler"

OnDisposed="Disposed event handler"

OnInit="Init event handler"

OnLoad="Load event handler"

OnPreRender="PreRender event handler"

OnUnload="Unload event handler"

PostBackUrl="uri"

runat="server"

/>
// LinkButtonExample.aspx

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

CodeBehind="LinkButtonExample.aspx.cs"
Inherits="LinkButtonExample.LinkButtonExample" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<p>It is a hyperlink style button</p>

</div>

<asp:LinkButton ID="LinkButton1" runat="server"


OnClick="LinkButton1_Click">javatpoint</asp:LinkButton>

<p>

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

</p>

</form>

</body>

</html>

// LinkButtonExample.aspx.cs
using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace LinkButtonExample

public partial class LinkButtonExample : System.Web.UI.Page

protected void LinkButton1_Click(object sender, EventArgs e)

Label1.Text = "Welcome to the javatpoint";

Image Button
The image button is used to display a clickable image,and a control that displays an image and
responds to mouse clicks on the image.

Imagebutton.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Backgroundchanging.aspx.cs"
Inherits="imagebutton.Backgroundchanging" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Label ID="lblimage" runat="server" ForeColor="#000066"


style="font-style: italic; text-decoration: underline; font-size: large; font-weight:
700"
Text="Wellcome To Application"></asp:Label>
<br />
<br />
<asp:ImageButton ID="imgbtnbackground" runat="server" Height="297px"
ImageUrl="~/image/imagebutton2.png" onclick="imgbtnbackground_Click"
Width="473px" />

<br />
<asp:Label ID="lblbackground" runat="server"></asp:Label>

</div>
</form>
</body>
</html>
Imagebutton.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace imagebutton
{
public partial class Backgroundchanging : System.Web.UI.Page
{
protected void imgbtnbackground_Click(object sender, ImageClickEventArgs e)
{
lblbackground.Text = e.X + " " + e.Y;
}
}
}
Hyperlink
It is a control that is used to create a hyperlink. It responds to a click event. We can use it to
refer any web page on the server.
To create HyperLink either we can write code or use the drag and drop facility of visual studio
IDE. This control is listed in the toolbox.
This is a server side control and ASP.NET provides own tag to create it.
user-form.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="user-form.aspx.cs"
Inherits="asp.netexample.user_form" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HyperLink ID="HyperLink1" runat="server" Text="JavaTpoint"
NavigateUrl="www.javatpoint.com"></asp:HyperLink>
</div>
</form>
</body>
</html>

DropDownList

The DropDownList is a web server control which is used to create an HTML Select component. It
allows us to select an option from the dropdown list. It can contain any number of items

ASP.NET provides a tag to create DropDownList for web application. The following is the Syntax of
DropDownList tag.

<asp:DropDownList id="DropDownList1" runat="server"


DataSource="<% databindingexpression %>"
DataTextField="DataSourceField"
DataValueField="DataSourceField"
AutoPostBack="True|False"
OnSelectedIndexChanged="OnSelectedIndexChangedMethod">
<asp:ListItem value="value" selected="True|False">
Text
</asp:ListItem>
</asp:DropDownList>

// DropDownListExample.aspx
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="DropDownListExample._Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<p>Select a City of Your Choice</p>
<div>
<asp:DropDownList ID="DropDownList1" runat="server" >
<asp:ListItem Value="">Please Select</asp:ListItem>
<asp:ListItem>New Delhi </asp:ListItem>
<asp:ListItem>Greater Noida</asp:ListItem>
<asp:ListItem>NewYork</asp:ListItem>
<asp:ListItem>Paris</asp:ListItem>
<asp:ListItem>London</asp:ListItem>
</asp:DropDownList>
</div>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
<br />
<br />
<asp:Label ID="Label1" runat="server" EnableViewState="False"></asp:Label>
</form>
</body>
</html>
// DropDownListExample.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DropDownListExample
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "")
{
Label1.Text = "Please Select a City";
}
else
Label1.Text = "Your Choice is: " + DropDownList1.SelectedValue;
}
}
}
ListBox Control
The ListBox Control provides us a user interface that will display the List of the items. From there, the
users can select one or more items from the List. We can use the ListBox to show the multiple columns, and
these columns can contain images and other controls.
For creating the ListBox, we will follow the two approaches in Windows Form. To create the ListBox
control, either we can use the Forms Designer at the time of the designing, or we can use the ListBox class
for creating control at the run time.
e.g.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ListBox box = new ListBox();
box.Location = new Point(300, 110);
box.Size = new Size(160, 103);
box.ForeColor = Color.Purple;
box.Items.Add(765);
box.Items.Add(875);
box.Items.Add(345);
// Now we will add ListBox control
// to the form
this.Controls.Add(box);
}
}
}
Panel control
The Panel control works as a container for other controls on the page. It controls the
appearance and visibility of the controls it contains. It also allows generating controls
programmatically.
<asp:Panel ID= "Panel1" runat = "server">
</asp:Panel>
The Panel control is derived from the WebControl class. Hence it inherits all the
properties, methods and events of the same. It does not have any method or event of its own.
e.g.
<asp:Panel ID="Panel1" runat="server" BorderColor="#990000" BorderStyle="Solid"
Borderstyle="width:1px" Height="116px" ScrollBars="Both" style="width:278px">

This is a scrollable panel.


<br />
<br />

<asp:Button ID="btnpanel" runat="server" Text="Button" style="width:82px" />


</asp:Panel>

ImageMap
The ImageMap control in ASP.NET 2.0 and onward versions can be used to create an image
that contains defined hot spot regions. When a user clicks a hot spot region, the control can
either generate a post back to the server or navigate to a specified URL.

There are three kinds of hot spot regions defined in ImageMap control.
• RectangleHotSpot
• CircleHotSpot
• PolygonHotSpot

The RectangleHotSpot defines rectangular hot spot regions. The CircleHotSpotdefines circle-
shaped ones and the PolygonHotSpot is used for irregularly shaped hot spot area.

Map.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="map.aspx.cs" Inherits="map" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<table>

<tr>

<td colspan="4">

<asp:ImageMap ID="india" runat="server" ImageUrl="~/Map.jpg" Height="500px" Width="887px"


HotSpotMode="PostBack" OnClick="india_Click" BackColor="#C0C000" BorderColor="DarkSlateGray"
ForeColor="Red">

<asp:CircleHotSpot Radius="7" X="215" Y="125" HotSpotMode="PostBack"


NavigateUrl="~/map.aspx" PostBackValue="bhuj" AlternateText="Bhuj" />

<asp:CircleHotSpot Radius="7" X="525" Y="95" HotSpotMode="PostBack"


NavigateUrl="~/map.aspx" PostBackValue="patan" />

<asp:CircleHotSpot Radius="7" X="565" Y="45" HotSpotMode="PostBack"


NavigateUrl="~/map.aspx" PostBackValue="ambaji" />

<asp:CircleHotSpot Radius="7" X="525" Y="150" HotSpotMode="PostBack"


NavigateUrl="~/map.aspx" PostBackValue="me" />

<asp:CircleHotSpot Radius="7" X="625" Y="120" HotSpotMode="PostBack"


NavigateUrl="~/map.aspx" PostBackValue="him" />

<asp:CircleHotSpot Radius="7" X="495" Y="195" HotSpotMode="PostBack"


NavigateUrl="~/map.aspx" PostBackValue="sure" />

<asp:CircleHotSpot Radius="7" X="565" Y="195" HotSpotMode="PostBack"


NavigateUrl="~/map.aspx" PostBackValue="ahd" /> </asp:ImageMap>

</td>

<td colspan="2" style="width: 364px">

<asp:Panel ID="p1" runat="server" Height="20px" Visible="false">

<asp:Label ID="lbl1" Text="CITY:Bhuj STATE:Gujarat" runat="server" Width="162px" Height="57px"


BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>
</asp:Panel>

<asp:Panel ID="p2" runat="server" Height="18px" Visible="false">

<asp:Label ID="lbl2" Text="CITY:Patan STATE:Gujarat" runat="server" Width="162px"


Height="45px" BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>

</asp:Panel>

<asp:Panel ID="p3" runat="server" Height="16px" Visible="false">

<asp:Label ID="lbl3" Text="CITY:Ambaji STATE:Gujarat" runat="server" Width="160px"


BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>

</asp:Panel>

<asp:Panel ID="p4" runat="server" Height="14px" Visible="false">

<asp:Label ID="lbl4" Text="CITY:Mehsana STATE:Gujarat" runat="server" Width="161px"


BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>

</asp:Panel>

<asp:Panel ID="p5" runat="server" Height="14px" Visible="false">

<asp:Label ID="lbl5" Text="CITY:Himatnagar STATE:Gujarat" runat="server" Width="161px"


BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>

</asp:Panel>

<asp:Panel ID="p6" runat="server" Height="14px" Visible="false">

<asp:Label ID="lbl6" Text="CITY:Surendranagar STATE:Gujarat" runat="server" Width="90px"


BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>

</asp:Panel>

<asp:Panel ID="p7" runat="server" Height="14px" Visible="false">

<asp:Label ID="lbl7" Text="CITY:Ahemdabad STATE:Gujarat" runat="server" Width="162px"


BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>

</asp:Panel>

</td>

</tr>

</table>

</div>

</form>

</body>
</html>

Map.aspx.cs

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class map : System.Web.UI.Page

protected void india_Click(object sender, ImageMapEventArgs e)

string aa = e.PostBackValue;

if(aa=="bhuj")

p1.Visible =true ;

p2.Visible = false;

p3.Visible = false;

p4.Visible = false;

p5.Visible = false;

p6.Visible = false;

p7.Visible = false;
}

else if(aa=="patan")

p1.Visible =false ;

p2.Visible =true ;

p3.Visible = false;

p4.Visible = false;

p5.Visible = false;

p6.Visible = false;

p7.Visible = false;

else if (aa == "ambaji")

p1.Visible = false;

p2.Visible = false;

p3.Visible = true;

p4.Visible = false;

p5.Visible = false;

p6.Visible = false;

p7.Visible = false;

else if (aa == "him")

p1.Visible = false;

p2.Visible = false;

p3.Visible = false ;

p5.Visible = true;
p4.Visible = false;

p6.Visible = false;

p7.Visible = false;

else if (aa == "me")

p1.Visible = false;

p2.Visible = false;

p3.Visible = false ;

p4.Visible = true;

p5.Visible = false;

p6.Visible = false;

p7.Visible = false;

else if (aa == "sure")

p1.Visible = false;

p2.Visible = false;

p3.Visible = false;

p5.Visible = false ;

p4.Visible = false;

p6.Visible = true;

p7.Visible = false;

}
else if (aa == "ahd")

p1.Visible = false;

p2.Visible = false;

p3.Visible = false;

p5.Visible = false ;

p4.Visible = false;

p7.Visible = true;

p6.Visible = false;

SiteMapPath

The SiteMapPath control basically is used to access web pages of the website from one
webpage to another. It is a navigation control and displays the map of the site related to its
web pages. This map includes the pages in the particular website and displays the name of
those pages. You can click on that particular page in the Site Map to navigate to that page. We
can say that the SiteMapPath control displays links for connecting to URLs of other pages. The
SiteMapPath control uses a property called SiteMapProvider for accessing data from
databases and it stores the information in a data source. The SiteMapProvider internally
utilizes the SiteMapProvider abstract class defined under the System.Web namespace. The
representation of the SiteMapPath control is as follows:
Root Node->Child Node

e.g.

<?xml version="1.0" encoding="utf-8" ?>

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >

<siteMapNode url="Default.aspx" title="myhomepage" description="">

<siteMapNode url="myweb1.aspx" title="myfirstpage" description="" />


<siteMapNode url="myweb2.aspx" title="mysecondpage" description="" />

</siteMapNode>

</siteMap>

e.g.

<?xmlversionxmlversion="1.0"encoding="utf-8" ?>

<siteMapxmlnssiteMapxmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">

<siteMapNodeurlsiteMapNodeurl="Home.aspx" title="Home" description="Home Page">

<siteMapNodeurlsiteMapNodeurl="ProductGroups.aspx" title="Product Group" description="Product Group


Page">

<siteMapNodeurlsiteMapNodeurl="Furnitures.aspx" title="Furnitures" description="Furniture Items Page"


/>

<siteMapNodeurlsiteMapNodeurl="PlasticItems.aspx" title="Plastics" description="Plastic Items Page" />

</siteMapNode>

<siteMapNodeurlsiteMapNodeurl="Aboutus.aspx" title="About Us" description="About Us Page" />

<siteMapNodeurlsiteMapNodeurl="Contactus.aspx" title="Contact Us" description="Contact Us Page" />

</siteMapNode>

</siteMap>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy