Index: SR - No. Practicals Date Sign 1
Index: SR - No. Practicals Date Sign 1
Index: SR - No. Practicals Date Sign 1
College,Bhiwandi
INDEX
1
Advance Web Programming B.N.N.College,Bhiwandi
2
Advance Web Programming B.N.N.College,Bhiwandi
PRACTICAL NO-1
1. Working with basic C# and ASP .NET
a. Create an application that obtains four int values from the user and
displays the product.
3
Advance Web Programming B.N.N.College,Bhiwandi
a. Create an application that obtains four int values from the user and
displays the product.
Step1:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace pract1_a
{
class Product
{
static void Main(string[] args)
{
int a, b, c, d, product;
Console.WriteLine("Enter four integers");
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
c = Convert.ToInt32(Console.ReadLine());
d = Convert.ToInt32(Console.ReadLine());
product = a * b * c * d;
Console.WriteLine("Product="+product);
Console.ReadKey();
}
}
}
Step2:-
4
Advance Web Programming B.N.N.College,Bhiwandi
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>
5
Advance Web Programming B.N.N.College,Bhiwandi
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click"
Text="Reset:" />
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label7" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label8" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label9" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label10" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label11" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
protected void Button1_Click(object sender, EventArgs e)
6
Advance Web Programming B.N.N.College,Bhiwandi
{
string s = TextBox1.Text;
Label2.Text = "String Length: "+s.Length;
Label3.Text = "Substring: " + s.Substring(4,3);
Label4.Text = "Upper String: " + s.ToUpper();
Label5.Text = "Lower String: " + s.ToLower();
string rev = "";
for (int i = s.Length - 1; i >= 0; i--)
{
rev = rev + s[i];
}
Label6.Text = "Reverse String: " + rev.ToString();
Label7.Text = "Replace 's' by 't' in String: " + s.Replace('s','t');
Label8.Text = "Insert 'u' in String: " + s.Insert(3,"u");
Label9.Text = "String Truncate: " + s.Trim();
Label10.Text = "Remove String: " + s.Remove(4);
Label11.Text = "Index of String: " + s.IndexOf('e');
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Label6.Text = "";
Label7.Text = "";
Label8.Text = "";
Label9.Text = "";
Label10.Text = "";
TextBox1.Text = "";
}
}
Output:-
7
Advance Web Programming B.N.N.College,Bhiwandi
8
Advance Web Programming B.N.N.College,Bhiwandi
namespace student
{
class Program
{
struct stud
{
public String stud_name, stud_id, c_name;
public int date, month, year;
}
static void Main(string[] args)
{
stud[] s = new stud[5];
for (int i = 0; i < 5; i++)
{
Console.WriteLine("Enter student id");
s[i].stud_id = Console.ReadLine();
Console.WriteLine("Enter student name");
s[i].stud_name = Console.ReadLine();
Console.WriteLine("Enter course name");
s[i].c_name = Console.ReadLine();
Console.WriteLine("Enter date of birth \n Enter the date(1- 31)");
s[i].date = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the month(1-12)");
s[i].month = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the year");
s[i].year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter student list:");
}
for (int i = 0; i < 5; i++)
{
Console.WriteLine("Student ID=" + s[i].stud_id);
Console.WriteLine("Student name=" + s[i].stud_name);
Console.WriteLine("Course name=" + s[i].c_name);
9
Advance Web Programming B.N.N.College,Bhiwandi
10
Advance Web Programming B.N.N.College,Bhiwandi
11
Advance Web Programming B.N.N.College,Bhiwandi
12
Advance Web Programming B.N.N.College,Bhiwandi
namespace fibonacci
{
class Program
{
static void Main(string[] args)
{
int num1 = 0;
int num2 = 1;
int num3;
Console.WriteLine(num1 + " " + num2);
for (int i = 0; i < 10; i++)
{
num3 = num1 + num2;
num1 = num2;
num2 = num3;
Console.WriteLine(num3);
Console.WriteLine(" ");
}
Console.ReadKey();
}
}
}
Step2:-
13
Advance Web Programming B.N.N.College,Bhiwandi
namespace primenumber
{
class Program
{
static void Main(string[] args)
{
int num, counter;
Console.WriteLine("Enter a number:");
num = Convert.ToInt32(Console.ReadLine());
for (counter = 2; counter <= num / 2; counter++)
{
if ((num % counter) == 0)
{
break;
14
Advance Web Programming B.N.N.College,Bhiwandi
}
}
if (num == 1)
{
Console.WriteLine(num + " is neither prime nor composite");
}
else if (counter <= (num / 2))
{
Console.WriteLine(num + " is not prime number");
}
else
{
Console.WriteLine(num + " is prime number");
}
Console.ReadLine();
}
}
}
Step2:-
namespace vowels
{
class Program
{
static void Main(string[] args)
{
int a;
15
Advance Web Programming B.N.N.College,Bhiwandi
char ch;
Console.WriteLine("Enter a character:");
a = Console.Read();
ch = Convert.ToChar(a);
switch (ch)
{
case 'a': Console.WriteLine(ch + " is a vowel");
break;
case 'e': Console.WriteLine(ch + " is a vowel");
break;
case 'i': Console.WriteLine(ch + " is a vowel");
break;
case 'o': Console.WriteLine(ch + " is a vowel");
break;
case 'u': Console.WriteLine(ch + " is a vowel");
break;
case 'A': Console.WriteLine(ch + " is a vowel");
break;
case 'E': Console.WriteLine(ch + " is a vowel");
break;
case 'I': Console.WriteLine(ch + " is a vowel");
break;
case 'O': Console.WriteLine(ch + " is a vowel");
break;
case 'U': Console.WriteLine(ch + " is a vowel");
break;
default:Console.WriteLine(ch + " is not a vowel");
break;
}
Console.ReadKey();
}
}
}
Step2:-
16
Advance Web Programming B.N.N.College,Bhiwandi
namespace foreachloop
{
class Program
{
static void Main(string[] args)
{
String[] str = { "AI", "AWP", "IOT", "JAVA", "SPM" };
foreach(String s in str)
{
Console.WriteLine(s);
}
Console.ReadKey();
}
}
}
Step2:-
17
Advance Web Programming B.N.N.College,Bhiwandi
namespace reverse
{
class Program
{
static void Main(string[] args)
{
int num, rev = 0, sum = 0, d;
Console.WriteLine("Enter any number:");
num = Convert.ToInt32(Console.ReadLine());
while (num != 0)
{
rev = rev * 10;
d = num % 10;
rev = rev + d;
sum = sum + d;
num = num / 10;
}
Console.WriteLine("Reverse of number=" + rev);
Console.WriteLine("Sum of digits=" + sum);
Console.ReadKey();
}
}
}
Step2:-
18
Advance Web Programming B.N.N.College,Bhiwandi
PRACTICAL NO-2
2. Working with Object Oriented C# and ASP .NET
a. Create simple application to perform following operations
i. Finding factorial Value
ii. Money Conversion
iii. Quadratic Equation
iv. Temperature Conversion
19
Advance Web Programming B.N.N.College,Bhiwandi
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace fact
{
class Program
{
static void Main(string[] args)
{
int num, i, fact=1;
Console.WriteLine("Enter a number");
num = Convert.ToInt32(Console.ReadLine());
Output:-
20
Advance Web Programming B.N.N.College,Bhiwandi
namespace moneyconversion
{
class Program
{
static void Main(string[] args)
{
int choice;
Console.WriteLine("Enter your Choice :\n 1- Dollar to Rupee \n 2- Euro to
Rupee \n 3- Malaysian Ringgit to Rupee ");
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
Double dollar, rupee, val;
Console.WriteLine("Enter the Dollar Amount :");
dollar = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter the Dollar Value :");
val = double.Parse(Console.ReadLine());
rupee = dollar * val;
Console.WriteLine("{0} Dollar Equals {1} Rupees", dollar, rupee);
break;
case 2:
Double Euro, rupe, valu;
Console.WriteLine("Enter the Euro Amount :");
Euro = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter the Euro Value :");
valu = double.Parse(Console.ReadLine());
rupe = Euro * valu;
Console.WriteLine("{0} Euro Equals {1} Rupees", Euro, rupe);
break;
case 3:
Double ringit, rup, value;
Console.WriteLine("Enter the Ringgit Amount :");
ringit = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter the Ringgit Value :");
value = double.Parse(Console.ReadLine());
rup = ringit * value;
21
Advance Web Programming B.N.N.College,Bhiwandi
Output:-
22
Advance Web Programming B.N.N.College,Bhiwandi
namespace quadequation
{
class Quadraticroots
{
double a, b, c;
23
Advance Web Programming B.N.N.College,Bhiwandi
Output:-
24
Advance Web Programming B.N.N.College,Bhiwandi
namespace temperature
{
class Program
{
static void Main(string[] args)
{
int celsius, faren;
Console.WriteLine("Enter the Temperature in Celsius(°C) : ");
celsius = int.Parse(Console.ReadLine());
faren = (celsius * 9) / 5 + 32;
Console.WriteLine("0Temperature in Fahrenheit is(°F) : " + faren);
Console.ReadLine();
}
}
}
25
Advance Web Programming B.N.N.College,Bhiwandi
Output:-
namespace methoverloading
{
class Program
{
public void addition(int a, int b)
{
Console.WriteLine("Addition of int values= "+(a+b));
}
public void addition(float a, float b)
{
Console.WriteLine("Addition of float values= "+(a+b));
}
static void Main(string[] args)
{
Program p=new Program();
p.addition(10,20);
26
Advance Web Programming B.N.N.College,Bhiwandi
p.addition(11.2f,13.4f);
Console.ReadKey();
}
}
}
Step2:-
Step1:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace singleinherit
{
class furniture
{
string material;
float price;
public void getdata()
{
Console.WriteLine("Enter material name:");
material = Console.ReadLine();
Console.WriteLine("Enter price:");
price = float.Parse(Console.ReadLine());
}
27
Advance Web Programming B.N.N.College,Bhiwandi
Step2:-
28
Advance Web Programming B.N.N.College,Bhiwandi
b. Hierarchical Inheritance
Programmer
c.employee manager
Step1:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace hierarchicalinherit
{
class employee
{
public void display()
{
Console.WriteLine("This is Employee class");
}
}
class programmer : employee
{
public void display()
{
29
Advance Web Programming B.N.N.College,Bhiwandi
Output:-
30
Advance Web Programming B.N.N.College,Bhiwandi
d. Multilevel Inheritance
stud
marks
result
Step1:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace multilevel
{
class person
{
int age;
String name;
public person(String s, int a)
{
name = s;
age = a;
}
public void show()
{
Console.WriteLine("Name=" + name);
31
Advance Web Programming B.N.N.College,Bhiwandi
Console.WriteLine("Age=" + age);
}
}
class employee : person
{
String designation;
public employee(String s, int a, String d)
: base(s, a)
{
designation = d;
}
public void show()
{
base.show();
Console.WriteLine("Designation=" + designation);
}
}
class payroll : employee
{
int salary;
public payroll(String s, int a, String d, int sal)
: base(s, a, d)
{
salary = sal;
}
public void show()
{
base.show();
Console.WriteLine("Salary=" + salary);
}
}
class program
{
static void Main(string[] args)
{
Console.WriteLine("\nShowing person's data");
person p = new person("Rakesh",33);
p.show();
Console.WriteLine("\nShowing employee's data");
employee e = new employee("Rakesh",33,"Deputy Manager");
e.show();
Console.WriteLine("\nShowing payroll data");
payroll p1=new payroll("Rakesh",33,"Deputy Manager",50000);
p1.show();
Console.ReadKey();
}
}
32
Advance Web Programming B.N.N.College,Bhiwandi
Step2:-
namespace constructoverloading
{
class construct
{
int x;
public construct(int a, int b)
{
33
Advance Web Programming B.N.N.College,Bhiwandi
Step2:-
iv. Interfaces
Step1:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
34
Advance Web Programming B.N.N.College,Bhiwandi
namespace interfaces
{
interface rect
{
void calculate1(float x, float y);
}
class circle
{
public void calculate2(float a)
{
Console.WriteLine("Area of circle= " + 3.14 * a * a);
}
}
class shape : circle, rect
{
public void calculate1(float x, float y)
{
Console.WriteLine("Area of rectangle= " + x * y);
}
}
class sample
{
static void Main(string[] args)
{
shape obj = new shape();
obj.calculate1(10.1f, 20.1f);
obj.calculate2(5.3f);
Console.ReadKey();
}
}
}
Step2:-
35
Advance Web Programming B.N.N.College,Bhiwandi
OUTPUT:
36
Advance Web Programming B.N.N.College,Bhiwandi
namespace except
{
class Program
{
static void Main(string[] args)
{
int x = 10, y = 0, z;
try
{
z = x / y;
}
catch (Exception e)
{
Console.Write("An Error Occured\n");
Console.Write(e.Message);
}
finally
{
Console.Write("\nFinally Block Occured");
y = 2;
z = x / y;
Console.Write("\nz=" + z);
}
Console.ReadKey();
}
}
}
Step2:-
37
Advance Web Programming B.N.N.College,Bhiwandi
PRACTICAL NO-3
3. Working with Web Forms and Controls
a. Create a simple web page with various sever controls to demonstrate
setting and use of their properties. (Example : AutoPostBack)
38
Advance Web Programming B.N.N.College,Bhiwandi
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>
39
Advance Web Programming B.N.N.College,Bhiwandi
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Name: "></asp:Label>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
<br />
<br />
40
Advance Web Programming B.N.N.College,Bhiwandi
<br />
<asp:Button ID="Button1" runat="server" Text="Display"
OnClick="Button1_Click1" />
<br />
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
protected void Button1_Click1(object sender, EventArgs e)
{
lblresult.Text += "Name:" + txtname.Text + "</br>" + "Address:" +
txtaddress.Text + "</br>";
if (rbmale.Checked == true)
lblresult.Text += "Gender:" + rbmale.Text + "</br>";
else
lblresult.Text += "Gender:" + rbfemale.Text + "</br>";
41
Advance Web Programming B.N.N.College,Bhiwandi
Output:-
42
Advance Web Programming B.N.N.College,Bhiwandi
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>
43
Advance Web Programming B.N.N.College,Bhiwandi
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
44
Advance Web Programming B.N.N.College,Bhiwandi
{
protected void Page_Load(object sender, EventArgs e)
{
Output:-
45
Advance Web Programming B.N.N.College,Bhiwandi
46
Advance Web Programming B.N.N.College,Bhiwandi
PRACTICAL NO-4
4. Working with Form Controls
a. Create a Registration form to demonstrate use of various Validation
controls.
47
Advance Web Programming B.N.N.College,Bhiwandi
Design View
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>
48
Advance Web Programming B.N.N.College,Bhiwandi
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
protected void Button1_Click(object sender, EventArgs e)
{
Label2.Text = TextBox1.Text;
}
}
Web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
</configuration>
Output:-
49
Advance Web Programming B.N.N.College,Bhiwandi
2 Compare Validator
Solution:-
Design View
50
Advance Web Programming B.N.N.College,Bhiwandi
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>
</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:CompareValidator ID="CompareValidator1" runat="server"
BackColor="White" ControlToCompare="TextBox1" ControlToValidate="TextBox2"
ErrorMessage="Enter correct values" ForeColor="Red"></asp:CompareValidator>
<br />
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OK" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Result:"></asp:Label>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
51
Advance Web Programming B.N.N.College,Bhiwandi
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = TextBox2.Text;
}
}
Web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
</configuration>
Output:-
52
Advance Web Programming B.N.N.College,Bhiwandi
Design View
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>
53
Advance Web Programming B.N.N.College,Bhiwandi
</div>
<asp:Label ID="Label1" runat="server" Text="Result:"></asp:Label>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = TextBox2.Text;
}
}
Web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
54
Advance Web Programming B.N.N.College,Bhiwandi
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
</configuration>
Output:-
Design View
55
Advance Web Programming B.N.N.College,Bhiwandi
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>
</div>
</form>
<p>
</p>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
56
Advance Web Programming B.N.N.College,Bhiwandi
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = TextBox1.Text;
}
}
Web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
</configuration>
Output:-
57
Advance Web Programming B.N.N.College,Bhiwandi
5 Custom Validator
Solution:-
Design View
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>
</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="Enter number which is divisible by 2"
ForeColor="Red"
OnServerValidate="CustomValidator1_ServletValidator"></asp:CustomValidator>
<br />
<br />
58
Advance Web Programming B.N.N.College,Bhiwandi
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = TextBox1.Text;
}
protected void CustomValidator1_ServletValidator(object source,
ServerValidateEventArgs args)
{
int num = int.Parse(TextBox1.Text);
if (num % 2 == 0)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
}
59
Advance Web Programming B.N.N.College,Bhiwandi
Web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="ValidationSettings"/>
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
Output:-
60
Advance Web Programming B.N.N.College,Bhiwandi
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>
</div>
</form>
</body>
</html>
61
Advance Web Programming B.N.N.College,Bhiwandi
XML File.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>beauty-wallpaper.jpg</ImageUrl>
<NavigateUrl>http://www.google.com</NavigateUrl>
<AlternateText>Google Site</AlternateText>
</Ad>
<Ad>
<ImageUrl>planet blue ice space.jpg</ImageUrl>
<NavigateUrl>http://www.facebook.com</NavigateUrl>
<AlternateText>Facebook Site</AlternateText>
</Ad>
<Ad>
<ImageUrl>rose.jpg</ImageUrl>
<NavigateUrl>http://www.gmail.com</NavigateUrl>
<AlternateText>Gmail Site</AlternateText>
</Ad>
</Advertisements>
Output:-
62
Advance Web Programming B.N.N.College,Bhiwandi
63
Advance Web Programming B.N.N.College,Bhiwandi
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<%@ Register Src="~/WebUserControl.ascx" TagPrefix="UC" TagName="student" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<UC:student ID="Studentcontrol" runat="server"/>
64
Advance Web Programming B.N.N.College,Bhiwandi
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Save"
/>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Result:"></asp:Label>
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
}
protected void Button1_Click(object sender, EventArgs e)
{
Label3.Text += "Your name is " + TextBox1.Text + " and you are from " +
TextBox2.Text;
}
}
WebUserControl.aspx.cs
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<h1>This is User Control</h1>
Output:-
65
Advance Web Programming B.N.N.College,Bhiwandi
66
Advance Web Programming B.N.N.College,Bhiwandi
PRACTICAL NO-5
5. Working with Navigation, Beautification and Master page.
a. Create Web Form to demonstrate use of Website Navigation controls
and Site Map.
67
Advance Web Programming B.N.N.College,Bhiwandi
Home.aspx
Web.sitemap
68
Advance Web Programming B.N.N.College,Bhiwandi
</siteMapNode>
</siteMapNode>
</siteMap>
Output:-
69
Advance Web Programming B.N.N.College,Bhiwandi
PRACTICAL NO-6
6. Working with Database
70
Advance Web Programming B.N.N.College,Bhiwandi
Code:
Default.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Def
ault"%>
<!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="48px"TextMode="MultiLine"
Width="206px"></asp:TextBox>
<br/>
<br/>
<asp:Button ID="Button1"runat="server"OnClick="Button1_Click"Text="ok"/>
<br/>
<br/>
<asp:TextBox ID="TextBox2"runat="server"Height="130px"TextMode="MultiLine"
Width="275px"></asp:TextBox>
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class_Default :System.Web.UI.Page
{
71
Advance Web Programming B.N.N.College,Bhiwandi
}
protected void Button1_Click(object sender, EventArgs e)
{
String connstr = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
SqlConnection con = new SqlConnection(connstr);
con.Open();
SqlCommand cmd = new SqlCommand(TextBox1.Text,con);
SqlDataReader sdr = cmd.ExecuteReader();
TextBox2.Text = "";
while (sdr.Read())
{
TextBox2.Text += Environment.NewLine;
for (inti = 0; i<sdr.FieldCount; i++)
TextBox2.Text += sdr[i].ToString().PadLeft(15);
}
sdr.Close();
con.Close();
}
}
Web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true"targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<connectionStrings>
<add name="connstr"connectionString="Data Source=.;InitialCatalog=db;Integrated
Security=True"/>
</connectionStrings>
</configuration>
OUTPUT:
72
Advance Web Programming B.N.N.College,Bhiwandi
73
Advance Web Programming B.N.N.College,Bhiwandi
74
Advance Web Programming B.N.N.College,Bhiwandi
CODE:
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class_Default :System.Web.UI.Page
{
protected voidPage_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String connstr = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
SqlConnection con = new SqlConnection(connstr);
con.Open();
SqlCommand cmd = new SqlCommand("select * from abc", con);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
Label1.Text += sdr["name"].ToString()+" "+sdr["id"].ToString()+"</br>" ;
}
sdr.Close();
con.Close();
}
}
Default.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Def
ault"%>
<!DOCTYPE.html>
<html xmlns="http://www.w3.org/1999/xhtml">
75
Advance Web Programming B.N.N.College,Bhiwandi
<head runat="server">
<title></title>
</head>
<body>
<form id="form1"runat="server">
<div>
</div>
</form>
</body>
</html>
Web.config
<?xmlversion="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true"targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<connectionStrings>
<add name="connstr" connectionString="Data Source=.;Initial Catalog=db; Integrated
Security=True"/>
</connectionStrings>
</configuration>
76
Advance Web Programming B.N.N.College,Bhiwandi
OUTPUT:
77
Advance Web Programming B.N.N.College,Bhiwandi
PRACTICAL NO-7
7. Working with Database
78
Advance Web Programming B.N.N.College,Bhiwandi
<!DOCTYPEhtml>
<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"
DataSourceID="SqlDataSource1"DataTextField="cname"DataValueField="country">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1"runat="server"ConnectionString="<%$
ConnectionStrings:dbConnectionString4 %>"SelectCommand="SELECT * FROM
[customer]"></asp:SqlDataSource>
<br/>
<br/>
<asp:Button ID="Button1"runat="server"OnClick="Button1_Click"Text="OK"/>
<br/>
<br/>
<asp:Label ID="Label1"runat="server"Text="you have to selected:"></asp:Label>
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
79
Advance Web Programming B.N.N.College,Bhiwandi
using System.Configuration;
public partial class_Default :System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
Protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "The country you have selected is:" + DropDownList1.SelectedValue;
if(IsPostBack==false)
{
string connstr=ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
SqlConnection con=new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand("Select Distinct country from customer",con );
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
DropDownList1.DataSource = reader;
DropDownList1.DataTextField = "country";
DropDownList1.DataBind();
reader.Close();
con.Close();
}
}
}
80
Advance Web Programming B.N.N.College,Bhiwandi
OUTPUT:
81
Advance Web Programming B.N.N.College,Bhiwandi
b) Create a web application for to display the phone no of an author using database.
CODE:
OUTPUT:
82
Advance Web Programming B.N.N.College,Bhiwandi
c) Create a web application for inserting and deleting record from a database.
(Using Execute-Non Query).
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
}
protected void Button2_Click(object sender, EventArgs e)
{
string connstr=ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
SqlConnection con=new SqlConnection(connstr);
string updatequery = "update person set
firstname=@firstname,lastname=@lastname,city=@city,phoneno=@phoneno,cno=@cno
where cno=@cno";
SqlCommand cmd=new SqlCommand(updatequery,con);
cmd.Parameters.AddWithValue("@cno", TextBox1.Text);
83
Advance Web Programming B.N.N.College,Bhiwandi
cmd.Parameters.AddWithValue("@firstname",TextBox2.Text);
cmd.Parameters.AddWithValue("@lastname",TextBox3.Text);
cmd.Parameters.AddWithValue("@city",TextBox4.Text);
cmd.Parameters.AddWithValue("@phoneno",TextBox5.Text);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text="Records Updated Successfully...!";
con.Close();
}
protected void Button3_Click(object sender, EventArgs e)
{
string connstr = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
SqlConnection con = new SqlConnection(connstr);
string deletequery = "delete from person where firstname=@firstname";
SqlCommand cmd = new SqlCommand(deletequery, con);
cmd.Parameters.AddWithValue("@firstname", TextBox1.Text);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "RecordsDeletedSuccessfully...!"; con.Close();
}
protected void Button4_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
Label1.Text = "";
}
protected void Button5_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
}
84
Advance Web Programming B.N.N.College,Bhiwandi
Default.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Def
ault"%>
<!DOCTYPEhtml>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1"runat="server">
<div>
<asp:LabelID="Label1"runat="server"Text="cno:"></asp:Label>
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<br/>
<br/>
<asp:Label ID="Label2"runat="server"Text="fname"></asp:Label>
<asp:TextBox ID="TextBox2"runat="server"></asp:TextBox>
<br/>
<br/>
<asp:Label ID="Label3"runat="server"Text="lname:"></asp:Label>
<asp:TextBox ID="TextBox3"runat="server"></asp:TextBox>
<br/>
<br/>
<asp:Label ID="Label4"runat="server"Text="city"></asp:Label>
<asp:TextBox ID="TextBox4"runat="server"></asp:TextBox>
<br/>
<br/>
<asp:Label ID="Label5"runat="server"Text="phoneno:"></asp:Label>
<asp:TextBox ID="TextBox5"runat="server"></asp:TextBox>
<br/>
<br/>
<asp:Button ID="Button1"runat="server" OnClick="Button1_Click"Text="insert"/>
<asp:Button ID="Button2"runat="server" OnClick="Button2_Click"Text="update"/>
<asp:Button ID="Button3"runat="server" OnClick="Button3_Click"Text="delete"/>
<asp:Button ID="Button4"runat="server" OnClick="Button4_Click"Text="clear"/>
<asp:Button ID="Button5"runat="server" OnClick="Button5_Click"Text="show"/>
85
Advance Web Programming B.N.N.College,Bhiwandi
<br/>
<br/>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="cno" HeaderText="cno" SortExpression="cno"/>
<asp:BoundField DataField="firstname" HeaderText="firstname"
SortExpression="firstname"/>
<asp:BoundField DataField="lastname" HeaderText="lastname"
SortExpression="lastname"/>
<asp:BoundField DataField="city" HeaderText="city" SortExpression="city"/>
<asp:BoundField DataField="phoneno" HeaderText="phoneno"
SortExpression="phoneno"/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:dbConnectionString%>"SelectCommand="SELECT * FROM
[person]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
OUTPUT:
86
Advance Web Programming B.N.N.College,Bhiwandi
87
Advance Web Programming B.N.N.College,Bhiwandi
88
Advance Web Programming B.N.N.College,Bhiwandi
89
Advance Web Programming B.N.N.College,Bhiwandi
90
Advance Web Programming B.N.N.College,Bhiwandi
PRACTICAL NO-8
8. Working with Data Controls
91
Advance Web Programming B.N.N.College,Bhiwandi
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource1.SelectCommand= "select * from customer where city= '" +
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>
</div>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="city" DataValueField="city">
</asp:DropDownList>
<br />
<br />
92
Advance Web Programming B.N.N.College,Bhiwandi
OUTPUT:
93
Advance Web Programming B.N.N.College,Bhiwandi
94
Advance Web Programming B.N.N.College,Bhiwandi
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
95
Advance Web Programming B.N.N.College,Bhiwandi
</EditItemTemplate>
<InsertItemTemplate>
id:
<asp:TextBox ID="idTextBox" runat="server" Text='<%# Bind("id") %>' />
<br />
cname:
<asp:TextBox ID="cnameTextBox" runat="server" Text='<%# Bind("cname") %>' />
<br />
city:
<asp:TextBox ID="cityTextBox" runat="server" Text='<%# Bind("city") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
id:
<asp:Label ID="idLabel" runat="server" Text='<%# Bind("id") %>' />
<br />
cname:
<asp:Label ID="cnameLabel" runat="server" Text='<%# Bind("cname") %>' />
<br />
city:
<asp:Label ID="cityLabel" runat="server" Text='<%# Bind("city") %>' />
<br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:dbConnectionString %>" SelectCommand="SELECT * FROM
[customer]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
96
Advance Web Programming B.N.N.College,Bhiwandi
OUTPUT:
97
Advance Web Programming B.N.N.College,Bhiwandi
}
protected void Button1_Click(object sender, EventArgs e)
{
string connstr = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
SqlConnection con = new SqlConnection(connstr);
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(connstr))
{
SqlCommand cmd = new SqlCommand("select * from customer", conn);
cmd.CommandType = CommandType.Text;
sda.SelectCommand = cmd;
sda.Fill(ds, "country");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
}
}
Default.aspx
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
98
Advance Web Programming B.N.N.College,Bhiwandi
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<connectionStrings>
<add name="connstr" connectionString="Data Source=.;Initial Catalog=db;Integrated
Security=True"/>
</connectionStrings>
</configuration>
OUTPUT:
99