0% found this document useful (0 votes)
87 views

AWP Practical 3-1

The document describes using web forms and controls in ASP.NET. It includes code examples for creating a web form with text boxes, radio buttons, and a drop down list. It also demonstrates using a calendar control, including displaying messages, vacations, selecting dates, and calculating date differences. The output displays the selected dates and settings of the calendar control.

Uploaded by

sushil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

AWP Practical 3-1

The document describes using web forms and controls in ASP.NET. It includes code examples for creating a web form with text boxes, radio buttons, and a drop down list. It also demonstrates using a calendar control, including displaying messages, vacations, selecting dates, and calculating date differences. The output displays the selected dates and settings of the calendar control.

Uploaded by

sushil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

T.Y.B.SC. (I.T.) - ASP.

NETWITHC#
IT-7152
2018-2019

Practical No: [3]: Working with Web Forms and Controls

a) Create a simple web page with various sever controls to demonstrate setting and use
of their properties. (Example : AutoPostBack)
GUI:-

Source Code: - Html Code

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


Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width:100%;
}
.style2
{
width:153px;
}
.style3
{
width:153px;
height:26px;
}
.style4
{
height:26px;
}
.auto-style1 {
width: 153px;
height: 28px;
}

Page 1
T.Y.B.SC. (I.T.) - ASP.NETWITHC#
IT-7152
2018-2019

.auto-style2 {
height: 28px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server" Text="Roll No">
</asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label2" runat="server" Text="Name">
</asp:Label></td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style1">
Class</td>
<td class="auto-style2">
<asp:RadioButton ID="RadioButton1" runat="server" Text="FY"/>
<asp:RadioButton ID="RadioButton2" runat="server" Text="SY"/>
<asp:RadioButton ID="RadioButton3" runat="server" Text="TY"/>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="Label4" runat="server" Text="Course"></asp:Label>
</td>
<td class="style4">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>B.Com</asp:ListItem>
<asp:ListItem>BMS</asp:ListItem>
<asp:ListItem>B.SC(IT)</asp:ListItem>
<asp:ListItem>B.Sc(CS)</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style3">
&nbsp;</td>
<td class="style4">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button"/>
</td>
</tr>
</table>
</div>
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
</form>
</body>

Page 2
T.Y.B.SC. (I.T.) - ASP.NETWITHC#
IT-7152
2018-2019

</html>

Source Code: - CS Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string s;
if (RadioButton1.Checked == true)
{
s = RadioButton1.Text;
}
else if (RadioButton2.Checked == true)
{
s = RadioButton1.Text;
}
else
{
s = RadioButton3.Text;
}
Label5.Text = "You have been enrolled in " + DropDownList1.SelectedItem;
Label5.Text += " in " + s;
}
}
}

Output:-

Page 3
T.Y.B.SC. (I.T.) - ASP.NETWITHC#
IT-7152
2018-2019

b) Demonstrate the use of Calendar control to perform following operations.

a) Display messages in a calendar control b) Display vacation in a calendar control

c) Selected day in a calendar control using style d) Difference between two calendar dates

GUI:-

Page 4
T.Y.B.SC. (I.T.) - ASP.NETWITHC#
IT-7152
2018-2019

Source Code: - Html Code

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


Inherits="WebApplicationsDiv2.CalenderControl" %>

<!DOCTYPE html>

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

<asp:Calendar ID="Calendar1" runat="server" BackColor="White"


BorderColor="#3366CC" BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-
Names="Verdana" Font-Size="8pt" ForeColor="#003399" Height="200px" Width="220px"
NextPrevFormat="ShortMonth" OnDayRender="Calender1_DayRender"
OnSelectionChanged="btnsetting_Click">
<DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
<NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="Red" Font-Bold="True" ForeColor="Yellow" />
<SelectorStyle BackColor="#000099" ForeColor="#336666" />
<TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px"
Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
<TodayDayStyle BackColor="#99CCCC" ForeColor="White" />

Page 5
T.Y.B.SC. (I.T.) - ASP.NETWITHC#
IT-7152
2018-2019

<WeekendDayStyle BackColor="#CCCCFF" />


</asp:Calendar>
<br />
<asp:Button ID="btnsetting" runat="server" OnClick="btnsetting_Click"
Text="Show Setting" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnreset" runat="server" Text="Reset Settings"
OnClick="btnreset_Click" />
<br />
<br />
<asp:Label ID="lbldates" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label2" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label3" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label4" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label5" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label6" runat="server"></asp:Label>

</div>
</form>
</body>
</html>

Source Code: - CS Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplicationsDiv2
{
public partial class CalenderControl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lbldates.Text = "You Selected these Dates:<br>";
foreach (DateTime dt in Calendar1.SelectedDates)
{
lbldates.Text += dt.ToShortDateString() + "<br/>";
}
}

protected void btnsetting_Click(object sender, EventArgs e)


{
Calendar1.Caption = "Harshal";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Saturday;
Calendar1.NextPrevFormat = NextPrevFormat.FullMonth;

Page 6
T.Y.B.SC. (I.T.) - ASP.NETWITHC#
IT-7152
2018-2019

Calendar1.TitleFormat = TitleFormat.Month;
Label5.Text = "Todays Date " + Calendar1.TodaysDate.ToShortDateString();
Label2.Text = "Ganpati Vacation Starts: 9-13-2018";
TimeSpan d = new DateTime(2018, 9, 13) - DateTime.Now;
Label3.Text = "Days Remaining for Ganpati Vacation: " + d.Days.ToString();
if (Calendar1.SelectedDate.ToShortDateString() == "9-13-2018")
{
Label4.Text = "<b>Ganpati Festival Starts</b>";
}
if (Calendar1.SelectedDate.ToShortDateString() == "9-23-2018")
{
Label4.Text = "<b>Ganpati Festival Starts</b>";
}
}
protected void Calender1_SelectionChanged(object Sender, EventArgs e)
{
Label4.Text = "You Selected Date=
"+Calendar1.SelectedDate.Date.ToString();
}
protected void Calender1_DayRender(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)
{
if (e.Day.Date.Day == 5 && e.Day.Date.Month == 9)
{
e.Cell.BackColor = System.Drawing.Color.Red;
Label lbl = new Label();
lbl.Text = "<b>Teachers day</b>";
e.Cell.Controls.Add(lbl);
Image g1 = new Image();
g1.ImageUrl="Images/Desert.jpg";
g1.Height=20;
g1.Width=20;
e.Cell.Controls.Add(g1);
}
if (e.Day.Date.Day == 13 && e.Day.Date.Month == 9)
{
Calendar1.SelectedDate = new DateTime(2018, 9, 12);
Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate,
Calendar1.SelectedDate.AddDays(10));
Label lbl1 = new Label();
lbl1.Text = "<br>Ganpati";
e.Cell.Controls.Add(lbl1);
}
}

protected void btnreset_Click(object sender, EventArgs e)


{
lbldates.Text = " ";
Label2.Text = " ";
Label3.Text = " ";
Label4.Text = " ";
Label5.Text = " ";
Calendar1.SelectedDates.Clear();
}

}
}

Output:-

Page 7
T.Y.B.SC. (I.T.) - ASP.NETWITHC#
IT-7152
2018-2019

Page 8

You might also like