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

awp_orginal

The document outlines practical exercises for working with C# and ASP.NET, including applications for basic arithmetic operations, string manipulations, Fibonacci series generation, prime number testing, and vowel checking. It also covers object-oriented programming concepts such as inheritance, interfaces, and various applications like factorial calculation, money conversion, quadratic equations, and temperature conversion. Each section includes source code examples and expected outputs for better understanding.

Uploaded by

Vimala Naikar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

awp_orginal

The document outlines practical exercises for working with C# and ASP.NET, including applications for basic arithmetic operations, string manipulations, Fibonacci series generation, prime number testing, and vowel checking. It also covers object-oriented programming concepts such as inheritance, interfaces, and various applications like factorial calculation, money conversion, quadratic equations, and temperature conversion. Each section includes source code examples and expected outputs for better understanding.

Uploaded by

Vimala Naikar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 92

PRACTICAL NO 1: Working with Basic C# and ASP.

NET

a. Create an application that obtains four int values from the user and displays
the product.

Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prac1a
{
class Program
{
static void Main(string[] args)
{
int n1, n2, n3, n4, Result;
Console.Write("Enter 1st number:");
n1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter 2nd number:");
n2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter 3rd number:");
n3 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter 4th number:");
n4 = Convert.ToInt32(Console.ReadLine());
Result = n1 * n2 * n3 * n4;
Console.WriteLine("Product of numbers=" + n1 + "*" + n2 + "*"+ n3 + "*" + n4 +
"= " + Result);
Console.ReadKey();
}
}
}

Output:-
b. Create an application to demonstrate string operations.

Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace pract1b
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a string:");
string string2 = Console.ReadLine();
string string3 = string.Copy(string2);
Console.WriteLine("copied string is:{0}", string3);
if (string3.Contains("ide"))
Console.WriteLine("The srting {0} contains the substring ide", string3);
else
Console.WriteLine("The string {0} does not contains the substring ide",
string3);
char[] arr = string3.ToCharArray();
int count = 0;
for(int i=0;i<arr.Length;i++)
{
if (arr[i] == 'a' || arr[i] == 'A')
count++;
}
Console.WriteLine("The string {0} has {1} occurences of the character 'a' or 'A'",
string3, count);
string2 = string2.Insert(5, "hello");
Console.WriteLine("The inserted string is {0}", string2);
string string1 = "asp.net";
if (string.Equals(string1, string3))
Console.WriteLine("{0} {1} are equal", string1, string3);
else
Console.WriteLine("{0} {1} are not equal", string1, string3);

string string4 = string.Concat(string1, string2);


Console.WriteLine("Concatenation of {0} and {1} is {2}", string1, string2,
string4);
string string5 = "Advanced Java";
Console.Write("The string {0} with character 'a' replaced is", string5);
string5 = string5.Replace('a', 'u');
Console.Write(string5);
Console.ReadKey();
}
}
}

Output:-

c. Create an application to demonstrate following operations

i. Generate Fibonacci series.


Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prac1di
{
class Program
{
static void Main(string[] args)
{
int a = 0, b = 1,c, i, n;
Console.WriteLine("**Fibonacci Series**");
Console.Write("Enter total fibonacci series:");
n = Convert.ToInt32(Console.ReadLine());
Console.Write(" " + a + " " + b);
for (i=2;i<=n;i++)
{
c = a + b;
a = b;
b = c;
Console.Write(" " + c);
}
Console.ReadKey();
}
}
}

Output:-

ii. Test for prime numbers.


Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prac1dii
{
class Program
{
static void Main(string[] args)
{
int i, n, a = 0;
Console.WriteLine("**Prime Numbers**");
Console.Write("Enter a number:");
n = Convert.ToInt32(Console.ReadLine());
for(i=1;i<=n;i++)
{
if (n % i == 0)
{
a++;
}
}
if (a==2)
Console.WriteLine("The number "+n+ " is a prime number");
else
Console.WriteLine("The number "+n+ " is not a prime number");
Console.ReadKey();
}
}
}
Output:-

iii. Test for vowels.


Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prac1diii
{
class Program
{
static void Main(string[] args)
{
char ch;
Console.Write("Enter a character:");
ch = (char)Console.Read();
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
Console.WriteLine(ch + " is a vowel");
break;
default:
Console.WriteLine(ch + " is not a vowel");
break;
}
Console.ReadKey();
}
}
}

Output:-

iv. Use of foreach loop with arrays

Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace prac1div
{
class Program
{
static void Main(string[] args)
{
int[] arr = { 10, 20, 30, 40, 50 };
foreach(int i in arr)
{
Console.WriteLine(i);
}
Console.ReadKey();
}
}
}
Output:-

PRACTICAL NO.2 : Working with Object Oriented C# and ASP.NET

a.Create simple application to perform following operations

i. Finding factorial Value


Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Factorial : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button_Click(object sender, EventArgs e)
{

int i, fact = 1, number;


number = Convert.ToInt32(TextBox.Text);
for (i = 1; i <= number; i++)
{
fact = fact * i;
}
lblResult.Text="Factorial of " + number + " is: " + fact;

}
}

Output:-

ii. Money Conversion

Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)


{
if (DropDownList1.SelectedItem.Value == "Rupee to Dollar")
{
float amount = Convert.ToSingle(TextBox.Text);
float dollar;
dollar = amount / 73;
lblResult.Text = amount + " Rupee Equals " + dollar + " dollar";
}
else if (DropDownList1.SelectedItem.Value=="Rupee to Euro")
{
float amount = Convert.ToSingle(TextBox.Text);
float euro;
euro = amount / 84;
lblResult.Text = amount + " Rupee Equals " + euro + " euro";

}
else
{
float amount = Convert.ToSingle(TextBox.Text);
float mr;
mr = amount / 17;
lblResult.Text = amount + " Rupee Equals " + mr + " malaysian ringgit";
}
}

Output:-
iii. Quadratic Equation

Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button_Click(object sender, EventArgs e)
{
int a, b, c;
a = Convert.ToInt32(TextBox1.Text);
b = Convert.ToInt32(TextBox2.Text);
c = Convert.ToInt32(TextBox3.Text);
float y = (b * b) - (4 * a * c);
double d = (-b + Math.Sqrt(y)) / (2 * a);
double x = (-b - Math.Sqrt(y)) / (2 * a);
Result.Text = "The roots of quadratic equation are " + d + " and " + x;
}
}
Output:-

iv. Temperature Conversion

Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if(DropDownList1.SelectedItem.Value=="CtoF")
{
float C = Convert.ToSingle(TextBox1.Text);
float F;
F = (C * 9 / 5) + 32;
Display.Text = "From Celsius to Farenhit " + F +"F";
}
else
{
float F = Convert.ToSingle(TextBox1.Text);
float C;
C = (F - 32) * 5 / 9;
Display.Text = "From Farenhit to Celsius " + C + "C";
}
}
}

Output:-

b. Create simple application to demonstrate use of following concepts

i. Inheritance (all types)

Single level Inheritance

Source code :

shape.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Singleinheritance
{
class shape
{
protected int length, breadth;
public void getDetails()
{
Console.Write("Enter length:");
length = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter breadth:");
breadth = Convert.ToInt32(Console.ReadLine());
}

}
}

rectangle.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Singleinheritance
{
class Rectangle:shape
{
int a;
public void calculatearea()
{
a = length * breadth;
Console.WriteLine("Area of rectangle is:{0}", a);
}
}
}

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Singleinheritance
{
class Program
{
static void Main(string[] args)
{
Rectangle r = new Rectangle();
Console.WriteLine();
r.getDetails();
Console.WriteLine();
r.calculatearea();
Console.ReadKey();
}
}

Output:

Multilevel Inheritance

Source code :

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prac2b
{
class Program
{
static void Main(string[] args)
{
Result r = new Result();
r.getDetails();
Console.WriteLine();
r.getMarks();
Console.WriteLine();
r.putDetails();
Console.WriteLine();
r.putMarks();
Console.WriteLine();
r.calculateTotal();
Console.WriteLine();
Console.ReadKey();
}
}
}
Student.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prac2b
{
class Student
{
protected int Roll_no;
protected string name;
public void getDetails()
{
Console.WriteLine("***Get Details of Student");
Console.WriteLine();
Console.Write("Enter Student roll_no:");
Roll_no = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter student name:");
name = Console.ReadLine();
}
public void putDetails()
{
Console.WriteLine("** Details of Student**");
Console.WriteLine();
Console.Write("Student Roll_no: {0}", Roll_no);
Console.WriteLine();
Console.Write("Student Name: {0}", name);
Console.WriteLine();
}
}
}
Test.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace prac2b
{
class Test:Student
{
protected int csharp, adv_java, ns, la, st;
public void getMarks()
{
Console.WriteLine("\n***Get Marks of the Student***");
Console.WriteLine();
Console.Write("Enter marks of Asp.net with csharp:");
csharp = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter marks of Advanced Java:");
adv_java = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter marks of Network Security:");
ns = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter marks of Linux administration:");
la = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter marks of Software Testing:");
st = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
}
public void putMarks()
{
Console.WriteLine("***Display Marks of the students***");
Console.WriteLine();
Console.WriteLine("Marks obtained in Asp.Net with c#: {0}", csharp);
Console.WriteLine("Marks obtained in Advanced Java {0}", adv_java);
Console.WriteLine("Marks obtained in Network Security: {0}", ns);
Console.WriteLine("Marks obtained in Linux administration: {0}", la);
Console.WriteLine("Marks obtained in Software Testing: {0}", st);
}

}
}
Result.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace prac2b
{
class Result:Test
{
int Total;
public void calculateTotal()
{
Console.WriteLine("Display total marks of the student");
Console.WriteLine();
Total = csharp + adv_java + ns + la + st;
Console.WriteLine("Total marks obtained by the student is: {0}", Total);
}
}
}

Output:
Hierarchical Inheritance

Source code :

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prac2biii
{
class Program
{
static void Main(string[] args)
{
Shape s = new Shape(2.2,4.2);
s.display();
Rectangle r = new Rectangle(2.2, 4.2, "rectangle");
r.area();
Triangle t = new Triangle(2.2, 4.2, "triangle");
t.area();
Console.ReadKey();

}
}
}
Shape.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prac2biii
{
class Shape
{
protected double height, width;

public Shape(double h,double w)


{
height = h;
width = w;

}
public void display()
{
Console.WriteLine("Height:{0}", height);
Console.WriteLine("Width:{0}", width);

}
}
}
Rectangle.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prac2biii
{
class Rectangle:Shape
{
string shape;
public Rectangle(double h,double w,string s):base(h,w)
{
shape= s;
}
public void area()
{
Console.WriteLine("Area of {0} = {1}", shape, height * width);
}
}
}
Triangle.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prac2biii
{
class Triangle:Shape
{
string shape;
public Triangle(double h,double w,string s):base(h,w)
{
shape = s;
}
public void area()
{
Console.WriteLine("Area of {0} = {1}", shape, 0.5 * height * width);
}
}
}

Output:

ii. Interfaces
Source code :

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac2bv
{
class Program
{
static void Main(string[] args)
{
Square s = new Square();
Circle c = new Circle();
Console.Write("Enter a number:");
int a = Convert.ToInt32(Console.ReadLine());
s.compute(a);
c.compute(a);
Console.ReadKey();
}
}
}
Area.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac2bv
{
interface Area
{
void compute(int a);
}
}
Circle.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac2bv
{
class Circle:Area
{
public void compute(int a)
{
Console.WriteLine("Area of circle is {0}", 3.14 * a * a);
}
}
}

Square.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac2bv
{
class Square:Area
{
public void compute(int a)
{
int i = a * a;
Console.WriteLine("Area of a square is {0}", i);
}
}
}

Output:
c.Create simple application to demonstrate use of Delegates and events

Delegates

Source Code:-

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyDelegate
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a number:");
int m = Convert.ToInt32(Console.ReadLine());
Delegate d = new Delegate();
MyDelegate md1 = new MyDelegate(Delegate.reverse);
int p = md1(m);
Console.WriteLine("The reverse of {0} is {1}", m, p);
MyDelegate md2 = new MyDelegate(Delegate.addition);
int q = md2(m);
Console.WriteLine("The addition of {0} is {1}", m, q);
MyDelegate md3 = new MyDelegate(Delegate.factorial);
int r = md3(m);
Console.WriteLine("The factorial of {0} is {1}", m, r);
Console.ReadKey();
}
}
}
Delegate.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyDelegate
{
public delegate int MyDelegate(int a);
class Delegate
{
public static int reverse(int a)
{
int d = 0, r = 0;
while (a > 0)
{
d = a % 10;
a = a / 10;
r = (r * 10) + d;
}
return r;
}
public static int addition(int a)
{
int d = 0, r = 0;
while (a > 0)
{
d = a % 10;
a = a / 10;
r = r + d;
}
return r;
}
public static int factorial(int a)
{
int f = 1;
for (int i = 1; i <= a; i++)
f = f * i;
return f;
}
}
}
Output:-
Events

Source Code:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Events
{
public delegate void MyEventHandler();
class Program
{
static event MyEventHandler handler;
static void Method1()
{
Console.WriteLine("Method 1 is invoked");
}
static void Method2()
{
Console.WriteLine("Method 2 is invoked");
}
static void Method3()
{
Console.WriteLine("Method 3 is invoked");
}
static void Main(string[] args)
{
handler += new MyEventHandler(Method1);
handler += new MyEventHandler(Method2);
handler += new MyEventHandler(Method3);
handler.Invoke();
Console.ReadKey();
}
}
}

Output:-

PRACTICAL NO.3: Working with Forms and Controls


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

Source Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
for(int i=0; i<ListBox1.Items.Count; i++)
{
if(ListBox1.Items[i].Selected==true)
{
TextBox1.Text = TextBox1.Text + " " + ListBox1.Items[i].Text;
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
lbleffects.Font.Size = int.Parse(DropDownList1.SelectedItem.Text);
}

protected void RadioButton1_CheckedChanged(object sender, EventArgs e)


{
lbleffects.BackColor = System.Drawing.Color.Red;
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
lbleffects.BackColor = System.Drawing.Color.Green;
}
protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
{
lbleffects.BackColor = System.Drawing.Color.Blue;
}
protected void chkbold_CheckedChanged(object sender, EventArgs e)
{
lbleffects.Font.Bold = true;
}

protected void chkitalic_CheckedChanged(object sender, EventArgs e)


{
lbleffects.Font.Italic = true;
}
protected void chkunder_CheckedChanged(object sender, EventArgs e)
{
lbleffects.Font.Underline = true;
}

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)


{
lbleffects.Text = DropDownList2.SelectedItem.Text;
}
}

Source Code
<%@ 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: 180px;
height: 261px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="View State Data"></asp:Label>
&nbsp;&nbsp;
<asp:Label ID="lblstr" runat="server"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Get Data" />
<br />
<br />
<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple">
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>C++</asp:ListItem>
<asp:ListItem>C#</asp:ListItem>
<asp:ListItem>Java</asp:ListItem>
</asp:ListBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Show"
/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server"
TextMode="MultiLine"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Select Color:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True"
GroupName="color" OnCheckedChanged="RadioButton1_CheckedChanged"
Text="Red" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True"
GroupName="color" OnCheckedChanged="RadioButton2_CheckedChanged"
Text="Green" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="RadioButton3" runat="server" AutoPostBack="True"
GroupName="color" OnCheckedChanged="RadioButton3_CheckedChanged"
Text="Blue" />
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Select special
formatting:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:CheckBox ID="chkbold" runat="server" AutoPostBack="True"
OnCheckedChanged="chkbold_CheckedChanged" Text="Bold" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:CheckBox ID="chkitalic" runat="server" AutoPostBack="True"
OnCheckedChanged="chkitalic_CheckedChanged" Text="Italic" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:CheckBox ID="chkunder" runat="server" AutoPostBack="True"
OnCheckedChanged="chkunder_CheckedChanged" Text="Underline" />
<br />
<br />
<asp:Label ID="Label4" runat="server" Text="Select size:"></asp:Label>
&nbsp;&nbsp;
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="Ten">10</asp:ListItem>
<asp:ListItem Value="fifteen">15</asp:ListItem>
<asp:ListItem Value="Twenty">20</asp:ListItem>
<asp:ListItem Value="twentyfive">25</asp:ListItem>
<asp:ListItem Value="thirty">30</asp:ListItem>
<asp:ListItem Value="thirtyfive">35</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Label ID="Label5" runat="server" Text="Select Subject:"></asp:Label>
&nbsp;&nbsp;
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem>AWP</asp:ListItem>
<asp:ListItem>NGT</asp:ListItem>
<asp:ListItem>LSA</asp:ListItem>
<asp:ListItem>SPM</asp:ListItem>
<asp:ListItem>IOT</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Label ID="lbleffects" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label6" runat="server" Text="Photo:"></asp:Label>
<br />
<br />
<asp:Image ID="Image1" runat="server" />
<img alt="Doraemon" class="auto-style1" src="Doraemon.png" /><br />
<br />
</div>
</form>
</body>
</html>
Output:
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

Source Code:

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

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


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnresult_Click(object sender, EventArgs e)
{
Calendar1.Caption = "Calendar";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;

Label2.Text = "Todays Date : " + Calendar1.TodaysDate.ToShortDateString();


Label3.Text = "Ganpati Vacation Start: 9-13-2018";
TimeSpan d = new DateTime(2018, 9, 13) - DateTime.Now;
Label4.Text = "Days remaining for Ganpati vacation: " + d.Days.ToString();
TimeSpan d1 = new DateTime(2018, 12, 31) - DateTime.Now;
Label5.Text = "Days remaining for New Year: " + d1.Days.ToString();
if (Calendar1.SelectedDate.ToShortDateString() == "9-13-2018")
Label3.Text = "<b>Ganpati Festival Start</b>";
if (Calendar1.SelectedDate.ToShortDateString() == "9-23-2018")
Label3.Text = "<b>Ganpati Festival End</b>";
}
protected void btnreset_Click(object sender, EventArgs e)
{
Label1.Text = " ";
Label2.Text = " ";
Label3.Text = " ";
Label4.Text = " ";
Label5.Text = " ";
Calendar1.SelectedDates.Clear();
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Label1.Text = "Your Selected Date: " + Calendar1.SelectedDate.Date.ToString();
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if(e.Day.Date.Day==5 && e.Day.Date.Month==9)
{
e.Cell.BackColor = System.Drawing.Color.LightSteelBlue;
Label lbl = new Label();
lbl.Text = "<br> Teachers Day! ";
e.Cell.Controls.Add(lbl);
Image g1 = new Image();
g1.ImageUrl = "td.jpg";
g1.Height = 30;
g1.Width = 20;
e.Cell.Controls.Add(g1);
}
if (e.Day.Date.Day == 3 && e.Day.Date.Month == 9)
{
e.Cell.BackColor = System.Drawing.Color.LightSteelBlue;
Label lbl = new Label();
lbl.Text = "<br> Janm ashtami ";
e.Cell.Controls.Add(lbl);
Image g2 = new Image();
g2.ImageUrl = "ja.jpg";
g2.Height = 30;
g2.Width = 20;
e.Cell.Controls.Add(g2);
}
}
if(e.Day.Date.Day == 13 && e.Day.Date.Month == 9)
{
Calendar1.SelectedDate = new DateTime(2018, 19, 12);
Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate,
Calendar1.SelectedDate.AddDays(10));
Label lbl1 = new Label();
lbl1.Text = "<br> Ganpati";
e.Cell.Controls.Add(lbl1);
}
}

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

<!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="White" BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt"
ForeColor="Black" Height="179px" NextPrevFormat="FullMonth" Width="305px"
ShowGridLines="True" OnDayRender="Calendar1_DayRender"
OnSelectionChanged="Calendar1_SelectionChanged">
<DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333"
VerticalAlign="Bottom" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" Font-
Bold="True" Font-Size="12pt" ForeColor="#333399" />
<TodayDayStyle BackColor="#CCCCCC" />
<WeekendDayStyle BackColor="#99CCFF" BorderColor="#000066"
BorderStyle="Solid" />
</asp:Calendar>
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnresult" runat="server" Text="Result"
OnClick="btnresult_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnreset" runat="server" Text="Reset"
OnClick="btnreset_Click" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server"></asp:Label>
<br />
<asp:Label ID="Label4" runat="server"></asp:Label>
<br />
<asp:Label ID="Label5" runat="server"></asp:Label>
<br />
<br />
</div>
</form>
</body>
</html>

Output:
PRACTICAL NO.4 : Working with Form Controls
a. Create a Registration form to demonstrate use of various Validation controls.
Source Code:

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

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>REGISTRATION FORM</title>
<style type="text/css">
.auto-style1 {
height: 26px;
}
</style>
</head>
<body>
<form id="form1" runat="server" title="REGISTRATION">
<table>
<tr><th colspan="3">REGISTRATION FORM</th></tr>
<tr>
<td class="auto-style1">User Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td>
<td class="auto-style1">
<asp:TextBox ID="username" runat="server"></asp:TextBox>
</td>
<td class="auto-style1">
&nbsp;&nbsp;&nbsp;<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server" ErrorMessage="This field cannot be
empty" ForeColor="Red" ControlToValidate="username"
></asp:RequiredFieldValidator>
&nbsp;&nbsp;&nbsp;
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="User Id have atleast digit less than 30 "
OnServerValidate="UserCustomValidate"
ControlToValidate="username" ForeColor="#3366CC"></asp:CustomValidator>
</td>
</tr>
<tr>
<td>Password : </td>
<td>
<asp:TextBox ID="txtpassword" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;&nbsp;&nbsp;<asp:RequiredFieldValidator
ID="RequiredFieldValidator2" runat="server" ErrorMessage="Field cannot be empty"
ControlToValidate="txtpassword" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Confirm Password: </td>
<td>
<asp:TextBox ID="txtconfirm" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
&nbsp;&nbsp;&nbsp;<asp:CompareValidator ID="CompareValidator"
runat="server" ErrorMessage="Passwords do not match"
ControlToCompare="txtpassword" ControlToValidate="txtconfirm"
ForeColor="Red"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>Email Id: </td>
<td>
<asp:TextBox ID="txtemail" runat="server"
TextMode="Email"></asp:TextBox>
</td>
<td>
&nbsp;&nbsp;&nbsp;
<asp:RequiredFieldValidator ID="RequiredFieldValidator4"
runat="server" ErrorMessage="Field cannot be empty" ControlToValidate="txtemail"
ForeColor="Red"></asp:RequiredFieldValidator>
&nbsp;&nbsp;&nbsp; <asp:RegularExpressionValidator
ID="RegularExpression" runat="server" ErrorMessage="Invalid email address"
ControlToValidate="txtemail" ForeColor="Red" ValidationExpression="\w+([-+.']\
w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

</td>
</tr>
<tr>
<td>Age : </td>
<td>
<asp:TextBox ID="txtage" runat="server"></asp:TextBox>
</td>
<td>
&nbsp;&nbsp;&nbsp;
<asp:RequiredFieldValidator ID="RequiredFieldValidator3"
runat="server" ErrorMessage="Field cannot be empty" ControlToValidate="txtage"
ForeColor="Red"></asp:RequiredFieldValidator>
&nbsp;&nbsp;
<asp:RangeValidator ID="RangeValidator1" runat="server"
ErrorMessage="Age should be in specified range 18-100" ControlToValidate="txtage"
ForeColor="#CC0066" MaximumValue="100" MinimumValue="18"
Type="Integer"></asp:RangeValidator>
</td>
</tr>
</table>
<p>
&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;&nbsp;
<asp:Button ID="Button1" runat="server" Text="Submit" BackColor="White"
ForeColor="#000066" />
</p>
<p>
&nbsp;</p>
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
ShowMessageBox="True" />
<p>
</p>
</form>
</body>
</html>
Registration.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void username_TextChanged(object sender, EventArgs e)
{

}
protected void UserCustomValidate(object source, ServerValidateEventArgs args)
{
string str = args.Value;
args.IsValid = false;
if(str.Length < 6 || str.Length > 25)
{
return;
}
bool capital = false;
foreach(char ch in str)
{
if(ch >='A' && ch <='Z')
{
capital = true;
break;
}
}
if(!capital)
{
return;
}
bool lower = false;
foreach(char ch in str)
{
if(ch >= 'a' && ch <='z')
{
lower = true;
break;
}
}
if (!lower)
{
return;
}
bool digit = false;
foreach(char ch in str)
{
if(ch >='0' && ch <='9')
{
digit = true;
break;
}
}
if(!digit)
{
return;
}
args.IsValid = true;
}

protected void Button1_Click(object sender, EventArgs e)


{

}
}

Output:
b. Create Web Form to demonstrate use of Adrotator Control.

Source Code:

Add.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>Rose.jpg</ImageUrl>
<NavigatorUrl></NavigatorUrl>
<AlternateText>Red Rose</AlternateText>
<Impression>1</Impression>
</Ad>
<Ad>
<ImageUrl>Orange.jpg</ImageUrl>
<NavigatorUrl></NavigatorUrl>
<AlternateText>Orange flower</AlternateText>
<Impression>2</Impression>
</Ad>
<Ad>
<ImageUrl>Barbie.jpg</ImageUrl>
<NavigatorUrl></NavigatorUrl>
<AlternateText>Barbie doll</AlternateText>
</Ad>
<Ad>
<ImageUrl>Guitar.jpg</ImageUrl>
<NavigatorUrl></NavigatorUrl>
<AlternateText>Guitar</AlternateText>
</Ad>
</Advertisements>

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

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:AdRotator ID="AdRotator1" runat="server"
AdvertisementFile="~/Adds.xml" Target="_blank" />
</div>
</form>
</body>
</html>

Output:
c. Create Web Form to demonstrate use User Controls.

Source Code:

Usercontroldispaly.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="UserControldisplay.aspx.cs" Inherits="UserControldisplay" %>
<%@ Register Src="~/Login.ascx" TagPrefix="uc" TagName="Login" %>

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

Login.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Login : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button2_Click(object sender, EventArgs e)
{
string uname= name.Text;
string pwd = password.Text;
if (uname.Equals("TYIT") && pwd.Equals("bscit123"))
{
Display.Text = "Hello " + name.Text;
}
else
{
Display.Text = "Username and password do not match";
}

}
}
Login.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Login.ascx.cs"
Inherits="Login" %>
<h3>User Control Example</h3>
<table>
<tr>
<td>User Name:&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="name" runat="server"></asp:TextBox>
<br />
<br />
</td>
</tr>
<tr>
<td>Password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="password" runat="server"></asp:TextBox>
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
<asp:Button ID="Savebtn" runat="server" Text="Save"
OnClick="Button2_Click" />
</td>
</tr>

<tr>
<td>
<asp:Label ID="Display" runat="server"></asp:Label>
<br />
</td>
</tr>
</table>

Output:
PRACTICAL NO.5 : Working with Navigation, Beautification and Master
Page

a. Create Web Form to demonstrate use of Website Navigation controls and


Site Map.

Source Code:

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>
<asp:Menu ID="Menu1" runat="server"
DataSourceID="SiteMapDataSource1"></asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:TreeView ID="TreeView1" runat="server"
DataSourceID="SiteMapDataSource1"></asp:TreeView>
</div>
</form>
</body>
</html>

Web.sitemap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/1.aspx" title="Root" description="Root">
<siteMapNode url="~/2.aspx" title="Admin" description="Admin" />
<siteMapNode url="~/3.aspx" title="User" description="User" />
</siteMapNode>
</siteMap>

1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="1.aspx.cs"
Inherits="_1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SiteMapPath ID="SiteMapPath1" runat="server" CurrentNodeStyle-
ForeColor="#9966FF" BorderStyle="NotSet"
ParentLevelsDisplayed="2"></asp:SiteMapPath>
<h3>Root page</h3>
</div>
</form>
</body>
</html>

2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="2.aspx.cs"
Inherits="_2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SiteMapPath ID="SiteMapPath1" runat="server"
ParentLevelsDisplayed="2"></asp:SiteMapPath>
<h3>Admin page</h3>
</div>
</form>
</body>
</html>

3.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="3.aspx.cs"
Inherits="_3" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SiteMapPath ID="SiteMapPath1" runat="server"
ParentLevelsDisplayed="2"></asp:SiteMapPath>
<h3>User page</h3>
</div>
</form>
</body>
</html>

Output:
b. Create a web application to demonstrate use of Master Page with applying
Styles and Themes for page beautification.

Source Code:-

Masterpage.master
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
.auto-style1 {
width: 536px;
}
</style>
</head>
<body style="width: 775px; height: 482px">
<form id="form1" runat="server">
<div>
<table>
<tr>
<td><img src="logo.jpg"</td>
<td class="auto-style1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label
ID="lbl1" runat="server" BorderStyle="None" ForeColor="#CC3300" Text="SIES
College of Commerce and Economics" Font-Bold="True" Font Height="28px" Font-
Size="X-Large"></asp:Label>
<br />
<asp:Label ID="Label1" runat="server" BackColor="#FF9933"
ForeColor="White" Height="46px" Text="Plot no.71/72, Sion Matunga Estate, TV
Chidambaran Marg, Sion, Mumbai, Maharashtra-400 022." Width="500px" Font-
Size="Large"></asp:Label>
</td>
</tr>
</table>
<table>
<tr>
<td rowspan="4">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="Home.aspx">Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="About.aspx">About</a>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;
<a href="Admission.aspx">Admission</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a runat="server" href="Research.aspx"
Text="Research.aspx">Research</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="news.aspx">
News</a></td>
</tr>
</table>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<footer>
<asp:Label ID="Label2" runat="server" Text="copyright @SIESCE"></asp:Label>
</footer>
</form>
</body>
</html>

About.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="About.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<p>
Welcome to SIES College of Commerce and Economics</p>
</asp:Content>

Admission.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="Admission.aspx.cs" Inherits="Admission" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<p>
<i class="fa fa-quote-left" style="background-color: transparent; box-sizing:
border-box; color: rgb(65, 105, 225); display: inline-block; font-family: FontAwesome;
font-size: 15px; font-size-adjust: none; font-stretch: 100%; font-style: normal; font-
variant: normal; font-weight: 400; letter-spacing: normal; line-height: 15px; orphans: 2;
outline-color: invert; outline-style: none; outline-width: 0px; text-align: left; text-
decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width:
0px; white-space: normal; word-spacing: 0px;"></i>
<span style="display: inline !important; float: none; background-color:
transparent; color: rgb(115, 115, 115); font-family: &quot;Lato&quot;,sans-serif; font-
size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing:
normal; line-height: 24px; orphans: 2; text-align: left; text-decoration: none; text-
indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal;
word-spacing: 0px;">&nbsp;&nbsp; There is </span><strong style="background-color:
transparent; box-sizing: border-box; color: rgb(65, 105, 225); font-family:
&amp;quot;Lato&amp;quot;,sans-serif; font-size: 15px; font-style: normal; font-variant:
normal; font-weight: 700; letter-spacing: normal; orphans: 2; outline-color: invert;
outline-style: none; outline-width: 0px; text-align: left; text-decoration: none; text-
indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal;
word-spacing: 0px;">NO DONATION - LINKED ADMISSION</strong><span
style="display: inline !important; float: none; background-color: transparent; color:
rgb(115, 115, 115); font-family: &quot;Lato&quot;,sans-serif; font-size: 15px; font-style:
normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height:
24px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-
transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing:
0px;">.
Do not pay money to anyone for seeking admission. Beware of unscrupulous
intermediaries (middle man and persons posing as agents) who, for their personal
gain, offer to intervene on your behalf. You could be deprieved both of admission of
your child as well as your hard earned money. &nbsp;&nbsp;</span><i class="fa fa-
quote-right" style="background-color: transparent; box-sizing: border-box; color:
rgb(65, 105, 225); display: inline-block; font-family: FontAwesome; font-size: 15px;
font-size-adjust: none; font-stretch: 100%; font-style: normal; font-variant: normal;
font-weight: 400; letter-spacing: normal; line-height: 15px;
orphans: 2; outline-color: invert; outline-style: none; outline-width: 0px; text-align: left;
text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-
width: 0px; white-space: normal; word-spacing: 0px;"></i></p>
</asp:Content>

Output:-

PRACTICAL NO.6 : Working with Database

a. Create a web application bind data in a multiline textbox by querying in


another textbox.

Source Code:-
Data.aspx.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Data : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button_Click(object sender, EventArgs e)
{

Web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6
/nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008
/define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
</compilers>
</system.codedom>
<connectionStrings>
<add name="Test" connectionString="Data Source=LAB2-46;Initial
Catalog=Text23;User ID=sa;Password=bscit@123"/>
</connectionStrings>
</configuration>

Data.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Data.aspx.cs"
Inherits="Data" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Height="81px"
Width="223px"></asp:TextBox>
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button" runat="server" OnClick="Button_Click" Text="Execute
query" />
<br />
<br />
Output:-<asp:TextBox ID="TextBox2" runat="server" Height="106px"
TextMode="MultiLine" Width="188px"></asp:TextBox>
</div>
</form>
</body>
</html>

Output:-
Create a database and a table ,insert the data

b. Create a web application to display records by using database.

Source Code:-

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlDataAdapter da;
DataSet ds;
SqlCommand cmd;
SqlDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{
string constr = "Data Source=LAB2-46;Initial Catalog=Text23;User
ID=sa;Password=bscit@123";
con = new SqlConnection(constr);
}

protected void btnConnected_Click(object sender, EventArgs e)


{
try
{
if (con.State == ConnectionState.Open)
con.Close();
con.Open();
cmd = new SqlCommand("Select * from Student23", con);
dr = cmd.ExecuteReader();
lblConnected.Text += "STUDENT<br/> ";
lblConnected.Text += "RollNo Name Address City Phone<br/> ";
while (dr.Read())
{
lblConnected.Text += dr[0].ToString() + "&nbsp;";
lblConnected.Text += dr[1].ToString() + "&nbsp;";
lblConnected.Text += dr[2].ToString() + "&nbsp;";
lblConnected.Text += dr[3].ToString() + "&nbsp;";
lblConnected.Text += dr[4].ToString() + "&nbsp;" + "<br/>";
}
}
catch (Exception ex)
{
lblConnected.Text = "Could not connect to the Database " + ex.Message;
}
finally
{
dr.Close();
con.Close();
}
}
protected void btnDisconnected_Click(object sender, EventArgs e)
{
try
{
if (con.State == ConnectionState.Open)
con.Close();
con.Open();
da = new SqlDataAdapter("select * from Student23", con);
ds = new DataSet();
da.Fill(ds);
lblDisconnected.Text += "STUDENT DETAILS <br/> ";
lblDisconnected.Text += "Rollno Name Address City Phone<br/> ";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
lblDisconnected.Text +=
ds.Tables[0].Rows[i].ItemArray[0].ToString() + "&nbsp;";
lblDisconnected.Text +=
ds.Tables[0].Rows[i].ItemArray[1].ToString() + "&nbsp;";
lblDisconnected.Text +=
ds.Tables[0].Rows[i].ItemArray[2].ToString() + "&nbsp;";
lblDisconnected.Text +=
ds.Tables[0].Rows[i].ItemArray[3].ToString() + "&nbsp;";
lblDisconnected.Text +=
ds.Tables[0].Rows[i].ItemArray[4].ToString() + "&nbsp;" + "<br/>";
}
}
catch (Exception ex)
{
lblDisconnected.Text = "Could not connect to the Database " +
ex.Message;
}
finally
{
con.Close();
}
}
}

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>
<asp:Button ID="btnConnected" runat="server" Text="Connected Data
Access"
onclick="btnConnected_Click" />
<br /> <br />
<asp:Label ID="lblConnected" runat="server"></asp:Label>
<br /> <br />
<asp:Button ID="btnDisconnected" runat="server"
Text="Disconnected Data Source" onclick="btnDisconnected_Click" />
<br /> <br />
<asp:Label ID="lblDisconnected" runat="server"></asp:Label>
</div>
</form>
</body>
</html>

Output:-
c. Demonstrate the use of Datalist link control.
PRACTICAL NO.7 : Working with Database

a. Create a web application to display Databinding using dropdownlist control.

Source Code:-
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
string connStr =
ConfigurationManager.ConnectionStrings["Text23ConnectionString"].ConnectionStrin
g;
SqlConnection con = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("Select Distinct City from
Student23",con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
//DropDownList1.DataSource = reader;
//DropDownList1.DataTextField = "City";
DropDownList1.DataBind();
reader.Close();
con.Close();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "The City Selected is : " + DropDownList1.SelectedValue;
}
}

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>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource2" DataTextField="Address" DataValueField="Address"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<
%$ ConnectionStrings:Text23ConnectionString2 %>" SelectCommand="SELECT
DISTINCT [Address] FROM [Student23]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<
%$ ConnectionStrings:Text23ConnectionString %>" SelectCommand="SELECT
DISTINCT [City] FROM [Student23]"></asp:SqlDataSource>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Select" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

Steps

Output:-
b. Create a web application for to display the phone no of an author using
database.

Source Code:-
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class prac7b : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack!=true)
{
string conStr =
ConfigurationManager.ConnectionStrings["Test2"].ConnectionString;
SqlConnection con = new SqlConnection(conStr);
SqlCommand cmd = new SqlCommand("Select Distinct Name,Phone from
Student2", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
DropDownList1.DataSource = reader;
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "Phone";
DropDownList1.DataBind();
reader.Close();
con.Close();

}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label.Text = DropDownList1.SelectedValue;
}
}

Output:-

c. Create a web application for inserting and deleting record from a database.
(Using Execute-Non Query).

Source Code:-
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Prac7c : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr
=ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
string InsertQuery = "Insert into Student2 values(@RollNo, @Name,@City,
@Address, @Phone)";
SqlCommand cmd = new SqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@RollNo", TextBox1.Text);
cmd.Parameters.AddWithValue("@Name", TextBox2.Text);
cmd.Parameters.AddWithValue("@City", TextBox3.Text);
cmd.Parameters.AddWithValue("@Address", TextBox4.Text);
cmd.Parameters.AddWithValue("@Phone", TextBox5.Text);
con.Open();
cmd.ExecuteNonQuery();
Label.Text = "Record Inserted Successfuly.";
con.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
string connStr
=ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
string InsertQuery = "Delete from Student2 where Name=@Name";
SqlCommand cmd = new SqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@Name", TextBox2.Text);
con.Open();
cmd.ExecuteNonQuery();
Label.Text = "Record Deleted Successfuly.";
con.Close();
}
}
Web.config
<connectionStrings>
<add name="connStr" connectionString="Data Source=LAB2-46;Initial
Catalog=Test2;User ID=sa;Password=bscit@123"/>
</connectionStrings>

Output:-
PRACTICAL NO.8 : Working with data controls

Create a web application to display Using Disconnected Data Access and


Databinding using GridView.

Source Code:-
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class prac8c : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button2_Click(object sender, EventArgs e)
{
string connStr
=ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
using(con)
{
SqlCommand cmd = new SqlCommand("Select * from Student2", con);
cmd.CommandType = CommandType.Text;
da.SelectCommand = cmd;
da.Fill(ds,"Student");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}

}
}

Web.config
<connectionStrings>
<add name="connStr" connectionString="Data Source=LAB2-46;Initial
Catalog=Test2;User ID=sa;Password=bscit@123"/>
</connectionStrings>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="prac8c.aspx.cs"
Inherits="prac8c" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Show
Data" />
<br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;
</div>
</form>
</body>
</html>

Output:-

PRACTICAL NO.9 : Working with GridView control

a. Create a web application to demonstrate use of GridView button column and


GridView events.
Steps:-
1.Add a grid view control and choose data source as new data source and then add
connection.

2. Click on new connection and then give the server name and give authentication as
sql server authentication and fill all the fields and click on ok.

3. Save the connection.


4. Click on add new column on grid view and select enable paging, enable sorting.

5. Choose a field type and do the following changes:-

i) choose a command type field.


ii) choose a button field for delete button.
6.Click on sqlDataSource and add a update query.

Update Table_name SET Column_names WHERE condition

Output:-
Updated Table

c. Create a web application to demonstrate GridView paging and Creating own


table format using GridView.

Source Code:-
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
{
if (!IsPostBack)
{
DataView();
}
}
}
private void DataView()
{
DataTable ds = new DataTable("MyTable");
DataColumn col1 = new DataColumn("Id", Type.GetType("System.Int32"));
DataColumn col2 = new DataColumn("P_Name", Type.GetType("System.String"));
DataColumn col3 = new DataColumn("Price", Type.GetType("System.String"));
ds.Columns.Add(col1);
ds.Columns.Add(col2);
ds.Columns.Add(col3);
DataRow dr;
for (int i = 0; i < 50; i++)
{
dr = ds.NewRow();
dr["Id"] = i;
dr["P_Name"] = "Product" + i;
dr["Price"] = (20 * (i + 1));
ds.Rows.Add(dr);
}
GridView1.DataSource = ds;
GridView1.AllowPaging = true;
GridView1.AllowSorting = true;
ViewState["dataTable"] = ds;
ViewState["sort"] = "Asc";
GridView1.DataBind();

}
protected void GridView1_PageIndexChanging(object sender,
GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
DataView();
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dt = (DataTable)ViewState["dataTable"];
if (dt.Rows.Count > 0)
{
if (Convert.ToString(ViewState["sort"]) == "Asc")
{
dt.DefaultView.Sort = "Desc";
ViewState["sort"] = "Desc";
}
else
{
dt.DefaultView.Sort = "Asc";
ViewState["sort"]= "Asc";
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
}

}
Output:-
PRACTICAL NO.10 : Working with AJAX and XML

a. Create a web application to demonstrate reading and writing operation with


XML.

Source Code:-
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string file = Path.Combine(Request.PhysicalApplicationPath, @"XMLFile.xml");
FileStream fs = new FileStream(file, FileMode.Create);
XmlTextWriter w = new XmlTextWriter(fs, null);
w.WriteStartDocument();
w.WriteStartElement("SuperProProductList");
w.WriteComment("This file is generated by the XmlTextWriter Class.");
// write the first product.
w.WriteStartElement("Product");
w.WriteAttributeString("ID", "1");
w.WriteAttributeString("Name", "Chair");
w.WriteStartElement("Price");
w.WriteString("49.33");
w.WriteEndElement();
w.WriteEndElement();
// write the second product.
w.WriteStartElement("Product");
w.WriteAttributeString("ID", "2");
w.WriteAttributeString("Name", "Car");
w.WriteStartElement("Price");
w.WriteString("43399.55");
w.WriteEndElement();
w.WriteEndElement();
// write the third product.
w.WriteStartElement("Product");
w.WriteAttributeString("ID", "3");
w.WriteAttributeString("Name", "Fresh Fruit Basket");
w.WriteStartElement("Price");
w.WriteString("49.99");
w.WriteEndElement();
w.WriteEndElement();
//Close the root element.
w.WriteEndElement();
w.WriteEndDocument();
w.Close();
Label1.Text = "Data Written Successfully";
}
protected void Button2_Click(object sender, EventArgs e)
{
string file = Path.Combine(Request.PhysicalApplicationPath, @"XMLFile.xml");
FileStream fs = new FileStream(file, FileMode.Open);
XmlTextReader r = new XmlTextReader(fs);
//Use a StringWriter to build up a string of HTML that describes the information
read from the XML document.
StringWriter writer = new StringWriter();
//parse the file and read each node.
while (r.Read())
{
switch (r.NodeType)
{
case XmlNodeType.Element:
ListBox1.Items.Add("<" + r.Name + ">");
break;
case XmlNodeType.Text:
ListBox1.Items.Add(r.Value);
break;
case XmlNodeType.EndElement:
ListBox1.Items.Add("<" + r.Name + ">");
break;
}
}
fs.Close();
// Copy the String content into a label to display it.
Label1.Text = "Data Read successfully";
}
}

Output:-
b. Create a web application to demonstrate Form Security and Windows
Security with proper Authentication and Authorization properties.

Source Code:-

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (authenticate(TextBox1.Text, TextBox2.Text))
{
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text,
CheckBox1.Checked);
Session["UserName"] = TextBox1.Text;
Response.Redirect("Default2.aspx");
}
else
{
Response.Write("Invalid Username or password");
}

}
private bool authenticate(string TextBox1, string TextBox2)
{
if (TextBox1.Equals("Admin"))
{
if (TextBox2.Equals("Admin123"))
{
return true;
}
}
if (TextBox1.Equals("Varsha"))
{
if (TextBox2.Equals("Admin123"))
{
return true;
}
}
return false;

}
}

Default2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] != null)
{
LabelR.Text = Session["UserName"].ToString();
}
}
}

Output:-

Web.config
<authentication mode="Forms"> <forms loginUrl="Default.aspx">
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
PRACTICAL NO.11 : Programs to create and use DLL

Steps:-
1.Add a class library

2. Write the code .

using System;
namespace ClassLibrary1
{
public class Prac11
{
public string upperConvert(string text)
{
return text.ToUpper();
}
public string lowerConvert(string text)
{
return text.ToLower();
}
}
}

3.Build the solution.

4. Add a new webite, giving the path of class library1 and add exixting item prac11.cs
using ClassLibrary1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
Prac11 t = new Prac11();
TextBox1.Text = t.upperConvert(TextBox1.Text);
}
protected void Button2_Click(object sender, EventArgs e)
{
Prac11 t = new Prac11();
TextBox1.Text = t.lowerConvert(TextBox1.Text);

}
}

Source Code:
<%@ 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>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Upper" />
<br />
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click"
Text="Lower" />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

</div>
</form>
</body>
</html>
Output:-

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