0% found this document useful (0 votes)
171 views10 pages

AWP Practical 3-2

The document describes using web forms and controls in ASP.NET. It includes two examples: 1. Creating a web form with controls like dropdown lists, textboxes, and buttons to customize card properties like background color, font, border style and more. 2. Using a calendar control to display messages, vacations, select dates, and compare dates. Properties like captions and date formats are demonstrated. Messages are added to specific dates.

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)
171 views10 pages

AWP Practical 3-2

The document describes using web forms and controls in ASP.NET. It includes two examples: 1. Creating a web form with controls like dropdown lists, textboxes, and buttons to customize card properties like background color, font, border style and more. 2. Using a calendar control to display messages, vacations, select dates, and compare dates. Properties like captions and date formats are demonstrated. Messages are added to specific dates.

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/ 10

T.Y.B.Sc. (I.T.

) – Advanced Web Programming –Paper (III) [Your Roll No]

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="card.aspx.cs"


Inherits="WebApplications.card" %>

<!DOCTYPE html>

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

<p id="l1">
choose a background colour</p>
<asp:DropDownList ID="dl1" runat="server" Height="20px" Width="127px">
</asp:DropDownList>
<p id="l2">

Page 1
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

Choose a font
</p>
<p>
<asp:DropDownList ID="dl2" runat="server">
</asp:DropDownList>
</p>
<p id="l3">
Font size</p>
<p>
<asp:TextBox ID="t1" runat="server" OnTextChanged="t1_TextChanged"></asp:TextBox>
</p>
<p id="l4">
Choose a border style</p>
<p>
<asp:RadioButtonList ID="rb1" runat="server">
<asp:ListItem>None</asp:ListItem>
<asp:ListItem>Double</asp:ListItem>
<asp:ListItem>Solid</asp:ListItem>
</asp:RadioButtonList>
</p>
<p>
<asp:CheckBox ID="c1" runat="server" Text="Add a default picture" />
</p>
<p id="l5">
Greeting text</p>
<p>
<asp:TextBox ID="t2" runat="server" Height="68px" Width="228px"></asp:TextBox>
</p>
<p>
<asp:Button ID="b1" runat="server" OnClick="b1_Click" Text="Update" style="height: 26px" />
</p>

<p>
</p>

</div>
<asp:Panel ID="p1" runat="server" Width="339px" Height="481px" HorizontalAlign="Center"
Style="POSITION: absolute; TOP: 16px; LEFT: 313px;" >
<br/>&nbsp;

<br />
<br />
<br />
<asp:Label ID="Lp6" runat="server"></asp:Label>
<br />
<br />
<br />
<br />
<br />
<br />
<asp:Image ID="i1" runat="server" />

Page 2
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

</asp:Panel>
</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;
using System.Drawing;
using System.Drawing.Text;
using System.ComponentModel;

namespace WebApplications
{
public partial class card : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
//Assign colours list
string[] colourArray = Enum.GetNames(typeof(KnownColor));
dl1.DataSource = colourArray;
dl1.DataBind();

//Assign font options


InstalledFontCollection fonts = new InstalledFontCollection() ;
foreach (FontFamily family in fonts.Families)
{
//Assign font
dl2.Items.Add(family.Name);
}
// Set border style options
string[] borderstyleArray = Enum.GetNames(typeof(BorderStyle));
rb1.DataSource = borderstyleArray;
rb1.DataBind();

dl1.SelectedIndex = 0;

}
}

protected void b1_Click(object sender, EventArgs e)


{

p1.BackColor = Color.FromName(dl1.SelectedItem.Text);

Page 3
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

Lp6.Font.Name = dl2.SelectedItem.Text;
if (c1.Checked)
{
i1.Visible = true;
i1.ImageUrl = "Images/Penguins.jpg";

}
else
{
i1.Visible = false;
}
Lp6.Text = t2.Text;
TypeConverter converter = TypeDescriptor.GetConverter(typeof(BorderStyle));
p1.BorderStyle = (BorderStyle)converter.ConvertFromString(rb1.SelectedItem.Text);
Lp6.Font.Name = dl2.SelectedItem.Text;
Lp6.Font.Name = dl2.SelectedItem.Text;
if (Int32.Parse(t1.Text) > 0)
{
Lp6.Font.Size = FontUnit.Point(Int32.Parse(t1.Text));
}
}

protected void t1_TextChanged(object sender, EventArgs e)


{

}
}
}

Output:-

Page 4
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

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 5
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

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" />

Page 6
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

<TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" Font-


Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
<TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
<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;
&nbsp;&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)
{

Page 7
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

lbldates.Text += dt.ToShortDateString() + "<br/>";


}
}

protected void btnsetting_Click(object sender, EventArgs e)


{
Calendar1.Caption = "Harshal";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Saturday;
Calendar1.NextPrevFormat = NextPrevFormat.FullMonth;
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);
}

Page 8
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

protected void btnreset_Click(object sender, EventArgs e)


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

}
}

Output:-

Page 9
T.Y.B.Sc. (I.T.) – Advanced Web Programming –Paper (III) [Your Roll No]

Page 10

You might also like