a. Server controls.
b. Web controls and demonstrate the use of AutoPostBack
c. Rich Controls (Calendar / Ad Rotator)
a. Server Controls:
Aspx:
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="PR3B.aspx.cs"Inherits="WebApplication1.PR3B"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<spanlang="en-us">
Location :
<asp:RadioButtonID="RadioButton1"runat="server"AutoPostBack="True"
GroupName="loc"Text="Mumbai"OnCheckedChanged="RadioButton1_CheckedChanged"/>
<asp:RadioButtonID="RadioButton2"runat="server"AutoPostBack="True"
GroupName="loc"Text="Pune"OnCheckedChanged="RadioButton2_CheckedChanged"/>
<br/>
<br/>
Theaters :
</span>
<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<br/>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Aspx.cs
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
namespace WebApplication1
{
publicpartialclassPR3B : System.Web.UI.Page
{
protectedvoidPage_Load(object sender, EventArgs e)
{
if (Page.IsPostBack )
{
DropDownList1.Items.Add("select A theatre");
}
}
protectedvoid RadioButton1_CheckedChanged(object sender, EventArgs e)
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add("select A theatre");
DropDownList1.Items.Add("CityGem");
DropDownList1.Items.Add("CityStar");
}
protectedvoid RadioButton2_CheckedChanged(object sender, EventArgs e)
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add("select A theatre");
DropDownList1.Items.Add("CityGold");
}
protectedvoid DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.Text == "CityGem")
{
Label1.Text = "movie1";
}
elseif (DropDownList1.Text == "CityStar")
{
Label1.Text = "movie2";
}
else
{
Label1.Text = "movie3";
}
}
}
}
OUTPUT:
b. Web controls and demonstrate the use of AutoPostBack:
.aspx file:
<asp:DropDownList ID="ddlFruits" runat="server" AutoPostBack = "true" OnSelectedIndexChanged = "OnSelectedIndexChanged">
<asp:ListItem Text="Mango" Value="1" />
<asp:ListItem Text="Apple" Value="2" />
<asp:ListItem Text="Banana" Value="3" />
<asp:ListItem Text="Guava" Value="4" />
<asp:ListItem Text="Orange" Value="5" />
</asp:DropDownList>
Program.cs file:
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
string message = ddlFruits.SelectedItem.Text + " - " + ddlFruits.SelectedItem.Value;
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + message + "');", true);
}
OUTPUT:
C. Rich Controls:
Aspx file:
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="PR3C.aspx.cs"Inherits="WebApplication1.PR3C"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:AdRotatorID="AdRotator1"runat="server"AdvertisementFile="~/XMLFile1.xml"/>
<h3> Your Birthday:</h3>
<asp:CalendarID="Calendar1"runat="server"SelectionMode="DayWeekMonth"onselectionchanged="Calendar1_SelectionChanged">
</asp:Calendar>
</div>
<p>Todays date is:
<asp:LabelID="lblday"runat="server"></asp:Label>
</p>
<p>Your Birday is:
<asp:LabelID="lblbday"runat="server"></asp:Label>
</p>
</form>
</body>
</html>
ASPX.CS file:
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
namespace WebApplication1
{
publicpartialclassPR3C : System.Web.UI.Page
{
protectedvoidPage_Load(object sender, EventArgs e)
{
}
protectedvoid Calendar1_SelectionChanged(object sender, EventArgs e)
{
lblday.Text = Calendar1.TodaysDate.ToShortDateString();
lblbday.Text = Calendar1.SelectedDate.ToShortDateString();
}
}
}
OUTPUT:
0 Comments