awp_orginal
awp_orginal
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);
Output:-
Output:-
Output:-
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:-
}
protected void Button_Click(object sender, EventArgs e)
{
}
}
Output:-
Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
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;
Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Output:-
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 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:-
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);
}
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>
<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>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Show"
/>
<asp:TextBox ID="TextBox1" runat="server"
TextMode="MultiLine"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Select Color:"></asp:Label>
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True"
GroupName="color" OnCheckedChanged="RadioButton1_CheckedChanged"
Text="Red" />
<asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True"
GroupName="color" OnCheckedChanged="RadioButton2_CheckedChanged"
Text="Green" />
<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>
<asp:CheckBox ID="chkbold" runat="server" AutoPostBack="True"
OnCheckedChanged="chkbold_CheckedChanged" Text="Bold" />
<asp:CheckBox ID="chkitalic" runat="server" AutoPostBack="True"
OnCheckedChanged="chkitalic_CheckedChanged" Text="Italic" />
<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>
<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>
<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;
}
protected void btnresult_Click(object sender, EventArgs e)
{
Calendar1.Caption = "Calendar";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;
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 />
<asp:Button ID="btnresult" runat="server" Text="Result"
OnClick="btnresult_Click" />
<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:
</td>
<td class="auto-style1">
<asp:TextBox ID="username" runat="server"></asp:TextBox>
</td>
<td class="auto-style1">
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server" ErrorMessage="This field cannot be
empty" ForeColor="Red" ControlToValidate="username"
></asp:RequiredFieldValidator>
<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>
<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>
<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>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4"
runat="server" ErrorMessage="Field cannot be empty" ControlToValidate="txtemail"
ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpression" runat="server" ErrorMessage="Invalid email address"
ControlToValidate="txtemail" ForeColor="Red" ValidationExpression="\w+([-+.']\
w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>Age : </td>
<td>
<asp:TextBox ID="txtage" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3"
runat="server" ErrorMessage="Field cannot be empty" ControlToValidate="txtage"
ForeColor="Red"></asp:RequiredFieldValidator>
<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>
<asp:Button ID="Button1" runat="server" Text="Submit" BackColor="White"
ForeColor="#000066" />
</p>
<p>
</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;
}
}
}
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:
<asp:TextBox ID="name" runat="server"></asp:TextBox>
<br />
<br />
</td>
</tr>
<tr>
<td>Password:
<asp:TextBox ID="password" runat="server"></asp:TextBox>
<br />
<br />
<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
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"> <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">
<a href="Home.aspx">Home</a>
<a href="About.aspx">About</a>
<a href="Admission.aspx">Admission</a>
<a runat="server" href="Research.aspx"
Text="Research.aspx">Research</a>  
;
<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" %>
Output:-
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=\"Web\" /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 />
<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
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);
}
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
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
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>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Show
Data" />
<br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<br />
<br />
</div>
</form>
</body>
</html>
Output:-
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.
Output:-
Updated Table
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
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
using System;
namespace ClassLibrary1
{
public class Prac11
{
public string upperConvert(string text)
{
return text.ToUpper();
}
public string lowerConvert(string text)
{
return text.ToLower();
}
}
}
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:-