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

Practical 1: A) Create An Application That Obtains Four Int Values From The User and Displays The Product. Code

The document contains code examples for several C# console and ASP.NET web applications that demonstrate basic programming concepts. The console applications include calculating the product of four user-input numbers, performing string operations, and collecting student data. The ASP.NET examples show how to calculate a factorial, convert money between currencies, and convert temperatures. The code examples are intended to teach object-oriented programming in C# and basic ASP.NET functionality.

Uploaded by

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

Practical 1: A) Create An Application That Obtains Four Int Values From The User and Displays The Product. Code

The document contains code examples for several C# console and ASP.NET web applications that demonstrate basic programming concepts. The console applications include calculating the product of four user-input numbers, performing string operations, and collecting student data. The ASP.NET examples show how to calculate a factorial, convert money between currencies, and convert temperatures. The code examples are intended to teach object-oriented programming in C# and basic ASP.NET functionality.

Uploaded by

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

Practical 1

A) Create an application that obtains four int values from the user and displays the product.
Code:-

using System;
class HelloWorld {
static void Main() {
int num1,num2,num3,num4,mul;
Console.WriteLine("Enter a Num1: ");
num1=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter a Num2: ");
num2=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter a Num3: ");
num3=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter a Num4: ");
num4=Convert.ToInt32(Console.ReadLine());
mul=num1*num2*num3*num4;
Console.WriteLine("Product of all number: "+mul);
}
}
Output:-

B) Create an application to demonstrate string operations.


Code:-
class HelloWorld {
static void Main() {
string s = "Namaste India";
Console.WriteLine("Trim: "+s.Trim());//Remove extra space from starting and ending.
Console.WriteLine("SubString: "+s.Substring(0,3));//Divide the String from the given range.
Console.WriteLine("ToUpper: "+s.ToUpper());//Convert the String into upperCase.
Console.WriteLine("ToLower: "+s.ToLower());//Convert the String into lowerCase.
Console.WriteLine("PadLeft: "+s.PadLeft(20,'@'));//add the string if the string not completing the range.
Console.WriteLine("Remove: "+s.Remove(0,4));//Remove the string from given range.
Console.WriteLine("Endwith: "+s.EndsWith('a'));//if the string end with the given string return boolean value.
Console.WriteLine("Indexof: "+s.IndexOf('I'));//Give the index of given string
string[] s1 = s.Split(' ');//Split the string on the basis of given string.
foreach(string s2 in s1){
Console.WriteLine(s2);

Shreya Kale T.21.41 Advanced Web Programming


}
string s3 =string.Join("Hello",s1);//join the string with the given string.
Console.WriteLine(s3);
}
}
Output:-

C) Create an application that receives the (Student Id, Student Name, Course Name, Date of Birth)
information from a set of students. The application should also display the information of all the students
once the data entered.
Code:-
using System;

class Student{
public int student_Id;
public string student_Name;
public string student_Course;
public string student_DOB;
public void set(){
Console.WriteLine("Enter the Stduent Id: ");
student_Id=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the Stduent Name: ");
student_Name=Console.ReadLine();
Console.WriteLine("Enter the Stduent Course: ");
student_Course=Console.ReadLine();
Console.WriteLine("Enter the Stduent Date of Birth: ");
student_DOB=Console.ReadLine();
}
public void get(){
Console.WriteLine("Student ID: "+student_Id);
Console.WriteLine("Student Name: "+student_Name);
Console.WriteLine("Student Course: "+student_Course);
Console.WriteLine("Student Date of Birth: "+student_DOB);
}
}

Shreya Kale T.21.41 Advanced Web Programming


class HelloWorld {
static void Main() {
Student[] s1 = new Student[2];
for(int i=0;i<2;i++){
s1[i]=new Student();
}
for(int i=0;i<2;i++){
s1[i].set();
}
for(int i=0;i<2;i++){
s1[i].get();
}
}
}
Output:-

D)Create an application to demonstrate following operations


i. Generate Fibonacci series.
Code:-
using System;
class HelloWorld {
static void Main() {
int x,a=0,b=1,i=0,c;
Console.WriteLine("How many fibonacci series number to print?");
x=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The Fibonacci Series:- ");
Console.WriteLine(a);
Console.WriteLine(b);
while(i<(x-2)){
c=a+b;
Console.WriteLine(c);
a=b;
b=c;
i++;
}

Shreya Kale T.21.41 Advanced Web Programming


}
}
Output:-

ii. Test for prime numbers.


Code:-
using System;
class HelloWorld {
static void Main() {
int num1,flag=0;
Console.WriteLine("Enter a Number: ");
num1=Convert.ToInt32(Console.ReadLine());
for(int i=2;i<=num1/2;i++){
if(num1%i==0){
flag=1;
}
}
if(flag==0){
Console.WriteLine("The given number is Prime Number.");
}else{
Console.WriteLine("The given number is Not a Prime Number.");
}
}
}
Output:-

Shreya Kale T.21.41 Advanced Web Programming


iii. Test for vowels
Code:-
using System;
class HelloWorld {
static void Main() {
Console.WriteLine("Enter a Character: ");
char a = Convert.ToChar(Console.ReadLine());
switch(char.ToUpper(a)){
case 'A':
Console.WriteLine("It is a Vowel.");
break;
case 'E':
Console.WriteLine("It is a Vowel.");
break;
case 'I':
Console.WriteLine("It is a Vowel.");
break;
case 'O':
Console.WriteLine("It is a Vowel.");
break;
case 'U':
Console.WriteLine("It is a Vowel.");
break;
default:
Console.WriteLine("It is A Constant.");
break;
}
}
}
Output:-

Shreya Kale T.21.41 Advanced Web Programming


iv. Use of foreach loop with arrays
Code:-
using System;
class HelloWorld {
static void Main() {
int[] a = new int[5];
Console.WriteLine("Enter a Number: ");
for(int i=0;i<5;i++){
a[i]=Convert.ToInt32(Console.ReadLine());
}
foreach(int i in a){
Console.WriteLine(i);
}
}
}
Output:-

v. Reverse a number and find sum of digits of a number.


Code:-
using System;

Shreya Kale T.21.41 Advanced Web Programming


class HelloWorld {
static void Main() {
int num1,ans=0,r=0;
Console.WriteLine("Enter a Number: ");
num1=Convert.ToInt32(Console.ReadLine());
while(num1>0){
r=num1%10;
ans=r+(ans*10);
num1=num1/10;
}
Console.WriteLine("The reverse of Given Number is "+ans);
}
}
Output:-

Practical 2

Shreya Kale T.21.41 Advanced Web Programming


Working with Object Oriented C# and ASP .NET

A) Create simple application to perform following operations


i) Finding factorial Value
Code:-

WebForm1.aspx:-
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication2.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter number"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" />
<br />
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>

WebForm1.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}

protected void Button1_Click1(object sender, EventArgs e)


{
int num = Convert.ToInt32(TextBox1.Text);

Shreya Kale T.21.41 Advanced Web Programming


int x = 1;
for (int i = 1; i <= num; i++)
{
x = i * x;
}
Label2.Text = ("The Factorial of Given Number is " + x);
}
}
}
Output:-

ii) Money Conversion


Code:-
WebForm2.aspx

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


Inherits="WebApplication2.WebForm2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter money"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Dollar" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Dinar" OnClick="Button2_Click" />
<br />
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>

WebForm2.aspx.cs

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

Shreya Kale T.21.41 Advanced Web Programming


using System.Web.UI.WebControls;

namespace WebApplication2
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
int a = Convert.ToInt32(TextBox1.Text);
int b = a / 82;
Label2.Text = (b+" Dollar");
}

protected void Button2_Click(object sender, EventArgs e)


{
int a = Convert.ToInt32(TextBox1.Text);
int b = a / 268;
Label2.Text = (b + " Dinar");

}
}
}

Output:-

iii) Temperature Conversion


Code:-
WebForm3.aspx

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


Inherits="WebApplication2.WebForm3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

Shreya Kale T.21.41 Advanced Web Programming


<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter Temperature:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Celsius to fahrenheit" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Fahrenheit to celsius" OnClick="Button2_Click" />
<br />
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>

WebForm3.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
int x = Convert.ToInt32(TextBox1.Text);
double d = (x * 1.8) + 32;
Label2.Text = (d + " Fahrenheit");
}

protected void Button2_Click(object sender, EventArgs e)


{
int x = Convert.ToInt32(TextBox1.Text);
double d = (x - 32) * 1 / 1.8;
Label2.Text = (d + " Celsius");
}
}
}

Output:-

Shreya Kale T.21.41 Advanced Web Programming


B) Create simple application to demonstrate use of following concepts
i) Function Overloading
Code:-

WebForm4.aspx

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


Inherits="WebApplication2.WebForm4" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter Number 1:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
Enter Number 2:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Area of Circle" OnClick="Button1_Click"
style="height-26px"/>
<asp:Button ID="Button2" runat="server" Text="Area of Square" OnClick="Button2_Click"/>
<asp:Button ID="Button3" runat="server" Text="Area of Rectangle" OnClick="Button3_Click" />
</div>
</form>
</body>
</html>

WebForm4.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm4 : System.Web.UI.Page
{
void area(int x)

Shreya Kale T.21.41 Advanced Web Programming


{
Response.Write("area of a circle:" + 3.14 * x * x);
}
void area(int x, int y)
{
Response.Write("area of a rectangle:" + x * y);
}
void area(double x)
{
Response.Write("area of a square:" + x * x);
}
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
int x = Convert.ToInt32(TextBox1.Text);
area(x);
}

protected void Button2_Click(object sender, EventArgs e)


{
double x = Convert.ToDouble(TextBox2.Text);
area(x);
}

protected void Button3_Click(object sender, EventArgs e)


{
int x = Convert.ToInt32(TextBox1.Text);
int y = Convert.ToInt32(TextBox1.Text);
area(x, y);
}
}
}

Output:-

ii) Inheritance
a) Simple Inheritance

Code:-
WebForm5.aspx.cs
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;

Shreya Kale T.21.41 Advanced Web Programming


using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
class A
{
public string show()
{
return ("class A");
}
}
class B : A
{
public string disp()
{
return ("class B");
}
}

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


{
protected void Page_Load(object sender, EventArgs e)
{
B ob = new B();
Response.Write(ob.show());
Response.Write("<br>" + ob.disp());
}
}
}
Output:-

b) Hierarchical Inheritance
Code:-
WebForm6.apsx.cs

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

namespace WebApplication2
{

Shreya Kale T.21.41 Advanced Web Programming


class A
{
public int x = 2;
}
class B : A
{
public int sqr()
{
return (x * x);
}
}
class C : A
{
public int cube()
{
return (x * x * x);
}
}

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


{
protected void Page_Load(object sender, EventArgs e)
{
B ob = new B();
C ob1 = new C();
Response.Write(ob.sqr());
Response.Write("<br>" + ob1.cube());
}
}
}

Output:-

iii) Constructor Overloading


Code:-
WebForm6.aspx.cs

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.UI;

Shreya Kale T.21.41 Advanced Web Programming


using System.Web.UI.WebControls;

namespace WebApplication2
{
public partial class WebForm6 : System.Web.UI.Page
{
int z;
public WebForm6()
{
z = 25;
}
public WebForm6(int y)
{
z = y;
}
public WebForm6(WebForm6 obj)
{
z = obj.z;
}
public int show()
{
return z;
}
protected void Page_Load(object sender, EventArgs e)
{
WebForm6 ob = new WebForm6();
Response.Write(ob.show());
WebForm6 ob1 = new WebForm6(15);
Response.Write("<br>" + ob1.show());
WebForm6 ob2 = new WebForm6();
Response.Write("<br>" + ob2.show());
}
}
}
Output:-

iv) Interfaces
Code:-
WebForm28.aspx.cs

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

Shreya Kale T.21.41 Advanced Web Programming


namespace WebApplication2
{
interface I1
{
string show();
}
interface I2
{
string show();
}
class D : I1, I2
{
string I1.show()
{
return ("abc");
}
string I2.show()
{
return ("<br/> xyz");
}
}

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


{
protected void Page_Load(object sender, EventArgs e)
{
I1 a = new D();
I2 b = new D();
Response.Write(a.show());
Response.Write(b.show());

}
}
}

Output:-

C) Create simple application to demonstrate use of following concepts


i) Using Delegates and events
Code:-
WebForm8.aspx.cs
using System;
using System.Collections.Generic;

Shreya Kale T.21.41 Advanced Web Programming


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

namespace WebApplication2

{
public delegate void dell(int x, int y);

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


{
public void add(int a, int b)
{
Response.Write(a + b);
}
public void sub(int a, int b)
{
Response.Write("<br>"+ (a - b));
}
protected void Page_Load(object sender, EventArgs e)
{

dell d1 = new dell(add);


dell d2 = new dell(sub);
d1(20, 10);
d2(20, 20);
}

}
}
Output:-

ii) Exception handling


Code:-
WebForm7.aspx

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


Inherits="WebApplication2.WebForm7" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

Shreya Kale T.21.41 Advanced Web Programming


<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter Number 1:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
Enter Number 2:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>

WebForm7.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
int x = Convert.ToInt32(TextBox1.Text);
int y = Convert.ToInt32(TextBox2.Text);
try
{
Label1.Text = (x / y).ToString();
}
catch(DivideByZeroException d)
{
Label1.Text=d.Message;
}
finally
{
Response.Write("Successfully Executed");
}
}
}
}

Shreya Kale T.21.41 Advanced Web Programming


Output:-

Practical 3
Working with Web Forms and Controls

a) Create a simple web page with various server controls to demonstrate setting and use of their properties.
(Example : AutoPostBack)
Code:-
WebForm9.aspx

Shreya Kale T.21.41 Advanced Web Programming


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm9.aspx.cs"
Inherits="WebApplication2.WebForm9" %>

<!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"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Nerul" Value="400706"></asp:ListItem>
<asp:ListItem Text="Seawood" Value="400707"></asp:ListItem>
<asp:ListItem Text="Vashi" Value="400708"></asp:ListItem>
</asp:DropDownList>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem Text="Small" Value="Small"></asp:ListItem>
<asp:ListItem Text="Medium" Value="Medium"></asp:ListItem>
<asp:ListItem Text="Large" Value="Large"></asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList2" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="RadioButtonList2_SelectedIndexChanged">
<asp:ListItem Text="Red" Value="Red"></asp:ListItem>
<asp:ListItem Text="Blue" Value="Blue"></asp:ListItem>
<asp:ListItem Text="Green" Value="Green"></asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButtonList ID="RadioButtonList3" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="RadioButtonList3_SelectedIndexChanged">
<asp:ListItem Text="Arial" Value="Arial"></asp:ListItem>
<asp:ListItem Text="Times New Roman" Value="Times New Roman"></asp:ListItem>
<asp:ListItem Text="Jokerman" Value="Jokerman"></asp:ListItem>
</asp:RadioButtonList>
<asp:CheckBox ID="CheckBox1" runat="server" Text="Underline" AutoPostBack="true"
OnCheckedChanged="CheckBox1_CheckedChanged" />
<asp:CheckBox ID="CheckBox2" runat="server" Text="Italic" AutoPostBack="true"
OnCheckedChanged="CheckBox2_CheckedChanged" />
<asp:CheckBox ID="CheckBox3" runat="server" Text="Bold" AutoPostBack="true"
OnCheckedChanged="CheckBox3_CheckedChanged" />
<br />
<asp:Label ID="Label1" runat="server" Text="SIES COllege of Nerul"></asp:Label>
</div>
</form>
</body>
</html>

WebForm9.aspx.cs

Shreya Kale T.21.41 Advanced Web Programming


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

namespace WebApplication2
{
public partial class WebForm9 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)


{
Label1.Text = DropDownList1.SelectedValue;
}

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)


{
if (RadioButtonList1.SelectedIndex == 0)
Label1.Font.Size = FontUnit.Small;
if (RadioButtonList1.SelectedIndex == 1)
Label1.Font.Size = FontUnit.Medium;
if (RadioButtonList1.SelectedIndex == 2)
Label1.Font.Size = FontUnit.Large;

protected void RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e)


{
if (RadioButtonList2.SelectedIndex == 0)
Label1.ForeColor = System.Drawing.Color.Red;
if (RadioButtonList2.SelectedIndex == 1)
Label1.ForeColor = System.Drawing.Color.Blue;
if (RadioButtonList2.SelectedIndex == 2)
Label1.ForeColor = System.Drawing.Color.Green;
}

protected void RadioButtonList3_SelectedIndexChanged(object sender, EventArgs e)


{
Label1.Font.Name = RadioButtonList3.SelectedValue;
}

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)


{
if (CheckBox1.Checked)
Label1.Font.Underline = true;

Shreya Kale T.21.41 Advanced Web Programming


else
Label1.Font.Underline = false;
}

protected void CheckBox2_CheckedChanged(object sender, EventArgs e)


{
if (CheckBox2.Checked)
Label1.Font.Italic = true;
else
Label1.Font.Italic = false;
}

protected void CheckBox3_CheckedChanged(object sender, EventArgs e)


{
if (CheckBox3.Checked)
Label1.Font.Bold = true;
else
Label1.Font.Bold = false;
}
}
}

Output:-

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


i) Display messages in a calendar control
Code:-
WebForm10.aspx

Shreya Kale T.21.41 Advanced Web Programming


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm10.aspx.cs"
Inherits="WebApplication2.WebForm10" %>

<!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" OnDayRender="Calendar1_DayRender"
OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
</div>
</form>
</body>
</html>

WebForm10.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
public partial class WebForm10 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Calendar1_SelectionChanged(object sender, EventArgs e)


{
Response.Write("selected date= " + Calendar1.SelectedDate.ToShortDateString());
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date.Day == 05 && e.Day.Date.Month == 09)
{
Label obj = new Label();
obj.Text = "teachers day";
e.Cell.Controls.Add(obj);
}
}
}

Shreya Kale T.21.41 Advanced Web Programming


}

Output:-

ii)Display vacation in a calendar control


Code:-
WebForm11.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm11.aspx.cs"
Inherits="WebApplication2.WebForm11" %>

<!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" OnDayRender="Calendar1_DayRender"
OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>

WebForm11.aspx.cs

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

Shreya Kale T.21.41 Advanced Web Programming


namespace WebApplication2
{
public partial class WebForm11 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Calendar1_SelectionChanged(object sender, EventArgs e)


{
Response.Write("selected date= " + Calendar1.SelectedDate.ToShortDateString());
}

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)


{
DateTime t1 = new DateTime(2023, 09, 19);
DateTime t2 = t1.AddDays(5);
Calendar1.SelectedDates.SelectRange(t1, t2);
}

}
}

Output:-

iii) Selected day in a calendar control using style


Code:-
WebForm12.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm12.aspx.cs"
Inherits="WebApplication2.WebForm12" %>

<!DOCTYPE html>

Shreya Kale T.21.41 Advanced Web Programming


<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"
OnSelectionChanged="Calendar1_SelectionChanged1"></asp:Calendar>
</div>
</form>
</body>
</html>

WebForm12.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm12 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Calendar1_SelectionChanged1(object sender, EventArgs e)
{
Response.Write("selected date= " + Calendar1.SelectedDate.ToShortDateString());
}
}
}

Output:-

Shreya Kale T.21.41 Advanced Web Programming


iv) Difference between two calendar dates
Code:-
WebForm13.aspx

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


Inherits="WebApplication2.WebForm13" %>

<!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" OnDayRender="Calendar1_DayRender"
OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

WebForm13.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

Shreya Kale T.21.41 Advanced Web Programming


namespace WebApplication2
{
public partial class WebForm13 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Calendar1_SelectionChanged(object sender, EventArgs e)


{
Response.Write("selected date= " + Calendar1.SelectedDate.ToShortDateString());
}

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)


{
TimeSpan t = new DateTime(2023, 11, 18) - DateTime.Now;
Label1.Text = ("no of days remaining for exam=" + t.Days.ToString());
}
}
}

Output:-

Shreya Kale T.21.41 Advanced Web Programming


Practical 4
Working with Form Controls
A)Create a Registration form to demonstrate use of various Validation controls
Code:-
WebForm14.aspx

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


Inherits="WebApplication2.WebForm14" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter Name:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1"
ErrorMessage="Please Enter Your Name"></asp:RequiredFieldValidator>
<br />
Enter Age:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox2"
MinimumValue="18" MaximumValue="60" Type="Integer"
ErrorMessage="Enter Valid Age"></asp:RangeValidator>
<br />

Shreya Kale T.21.41 Advanced Web Programming


Enter Moblie Number:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="Enter Valid Mobile Number" ControlToValidate="TextBox3"
OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
<br />
Enter EmailId:<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox4" ValidationExpression="\S+\@\S+\.\S+"
ErrorMessage="Enter Valid EmailId"></asp:RegularExpressionValidator>
<br />
Enter Password:<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox5" ErrorMessage="Enter Password"></asp:RequiredFieldValidator>
<br />
Re-enter Password:<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="Textbox6" ControlToCompare="TextBox5" Operator="Equal"
ErrorMessage="Password Mismatch"></asp:CompareValidator>
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"/>

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

WebForm14.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm14 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)


{
if (args.Value.Length == 10)
args.IsValid = true;
else
args.IsValid = false;

Shreya Kale T.21.41 Advanced Web Programming


}

protected void Button1_Click(object sender, EventArgs e)


{
if (Page.IsValid)
Response.Write("Data Submitted");
}
}
}
Web.Config
<appSettings>
<add key="validationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>

Output:-

b) Create Web Form to demonstrate use of Adrotator Control.


Code:-
WebForm15.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm15.aspx.cs"
Inherits="WebApplication2.WebForm15" %>

<!DOCTYPE html>

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

Shreya Kale T.21.41 Advanced Web Programming


<div>
<asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="XMLFile1.xml"/>
</div>
</form>
</body>
</html>

XMLFile1.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>google.png</ImageUrl>
<NavigateUrl>https://www.google.com/</NavigateUrl>
<AlternateText>Google</AlternateText>
<Keyword>Google</Keyword>
<Impressions>50</Impressions>
</Ad>
<Ad>
<ImageUrl>download.png</ImageUrl>
<NavigateUrl>https://mail.google.com/</NavigateUrl>
<AlternateText>Gmail</AlternateText>
<Keyword>Google</Keyword>
<Impressions>20</Impressions>
</Ad>
</Advertisements>

Output:-

c) Create Web Form to demonstrate use of User Controls.


Code:-
WebUserControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs"
Inherits="WebApplication2.WebUserControl1" %>
<asp:Calendar ID="Calendar1" runat="server"
OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

WebUserControl.ascx.cs

Shreya Kale T.21.41 Advanced Web Programming


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

namespace WebApplication2
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Calendar1_SelectionChanged(object sender, EventArgs e)


{
Label1.Text = Calendar1.SelectedDate.ToShortDateString();
}
}
}

WebForm16.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm16.aspx.cs"
Inherits="WebApplication2.WebForm16" %>

<%@ Register Src="~/WebUserControl1.ascx" TagPrefix="uc1" TagName="WebUserControl1" %>


<!DOCTYPE html>

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

Output:-

Shreya Kale T.21.41 Advanced Web Programming


WebForm17.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm17.aspx.cs"
Inherits="WebApplication2.WebForm17" %>
<%@ Register Src="~/WebUserControl1.ascx" TagPrefix="uc1" TagName="WebUserControl1" %>
<!DOCTYPE html>

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

Output:-

Shreya Kale T.21.41 Advanced Web Programming


WebForm18.aspx

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


Inherits="WebApplication2.WebForm18" %>
<%@ Register Src="~/WebUserControl1.ascx" TagPrefix="uc1" TagName="WebUserControl1" %>
<!DOCTYPE html>

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

Output:-

Shreya Kale T.21.41 Advanced Web Programming


Practical 5
Working with Navigation, Beautification and Master page.
a)Create Web Form to demonstrate use of Website Navigation controls and Site Map.
Code:-

Shreya Kale T.21.41 Advanced Web Programming


Site.Master
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs"
Inherits="WebApplication2.SiteMaster" %>
<link href="App_Themes/Theme1/StyleSheet1.css" rel="stylesheet" />

<!DOCTYPE html>

<html lang="en">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:100%;">
<tr>
<td colspan="2">Welcome.....
<asp:SiteMapPath ID="SiteMapPath1" runat="server"></asp:SiteMapPath>
</td>
</tr>

<tr>
<td>
<asp:Menu ID="Menu1" runat="server">
<Items>
<asp:MenuItem Text="SPM" NavigateUrl="~/WebForm20.aspx">
<asp:MenuItem Text="AWP" NavigateUrl="~/WebForm21.aspx"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="NGT" NavigateUrl="~/WebForm20.aspx">
<asp:MenuItem Text="AI" NavigateUrl="~/WebForm21.aspx"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="IOT" NavigateUrl="~/WebForm20.aspx"></asp:MenuItem>
</Items>
</asp:Menu>

<asp:TreeView ID="TreeView1" runat="server">


<Nodes>
<asp:TreeNode Text="SPM" NavigateUrl="~/WebForm21.aspx">
<asp:TreeNode Text="AWP" NavigateUrl="~/WebForm20.aspx"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="NGT" NavigateUrl="~/WebForm21.aspx">
<asp:TreeNode Text="AI" NavigateUrl="~/WebForm20.aspx"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="IOT" NavigateUrl="~/WebForm21.aspx"></asp:TreeNode>
</Nodes>
</asp:TreeView>
&nbsp;</td>
<td> <asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
&nbsp;</td>

Shreya Kale T.21.41 Advanced Web Programming


</tr>
</table>

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

WebForm20.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"


CodeBehind="WebForm20.aspx.cs" Inherits="WebApplication2.WebForm20" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
SPM
</asp:Content>

WebForm21.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="WebForm21.aspx.cs" Inherits="WebApplication2.WebForm21" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
AWP
</asp:Content>

Web.sitemap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="SPM" description="">
<siteMapNode url="" title="AWP" description="" />
<siteMapNode url="" title="AI" description="" />
<siteMapNode url="" title="IOT" description="" />
<siteMapNode url="" title="NGT" description="" />
</siteMapNode>
</siteMap>

StyleSheet.css
body {
background-color: bisque;
color: sandybrown;
font-size: xx-large;
font-family: Jokerman;
}

Output:-

Shreya Kale T.21.41 Advanced Web Programming


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

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs"


Inherits="WebApplication2.SiteMaster" %>

<!DOCTYPE html>

<html lang="en">
<head runat="server">
<title></title>
<link href="App_Themes/Theme1/StyleSheet1.css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>

WebForm19.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"


CodeBehind="WebForm19.aspx.cs" Inherits="WebApplication2.WebForm19" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
SIES(Nerul) College
</asp:Content>

StyleSheet1.css

body {
background-color: bisque;
color: sandybrown;
font-size: xx-large;
font-family: Jokerman;
}

Shreya Kale T.21.41 Advanced Web Programming


Output:-

c) Create a web application to demonstrate various states of ASP.NET Pages.


Code:-
ViewState
WebForm22.aspx

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


Inherits="WebApplication2.WebForm22" %>

<!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"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>

WebForm22.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm22 : System.Web.UI.Page
{
int x = 1;
protected void Page_Load(object sender, EventArgs e)

Shreya Kale T.21.41 Advanced Web Programming


{
if (!IsPostBack)
{
TextBox1.Text = "0";
}

protected void Button1_Click(object sender, EventArgs e)


{
if (ViewState["a"] != null)
{
x = Convert.ToInt32(ViewState["a"]) + 1;
}
TextBox1.Text = x.ToString();
ViewState["a"] = x;

}
}
}
Output:-

Session State
WebForm23.aspx

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


Inherits="WebApplication2.WebForm23" %>

<!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"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>

Shreya Kale T.21.41 Advanced Web Programming


WebForm23.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm23 : System.Web.UI.Page
{
int x = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBox1.Text = "0";
}

protected void Button1_Click(object sender, EventArgs e)


{
if (Session["a"] != null)
{
x = Convert.ToInt32(Session["a"]) + 1;
}
TextBox1.Text = x.ToString();
Session["a"] = x;

}
}
}
Output:-

Shreya Kale T.21.41 Advanced Web Programming


Application State
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm24.aspx.cs"
Inherits="WebApplication2.WebForm24" %>

<!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"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>

WebForm24.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm24 : System.Web.UI.Page
{
int x = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBox1.Text = "0";
}

Shreya Kale T.21.41 Advanced Web Programming


}

protected void Button1_Click(object sender, EventArgs e)


{
if (Application["a"] != null)
{
x = Convert.ToInt32(Application["a"]) + 1;
}
TextBox1.Text = x.ToString();
Application["a"] = x;

}
}
}

Output:-

Shreya Kale T.21.41 Advanced Web Programming


Practical 6
Working with Database
a) Create a web application bind data in a multiline textbox by querying in another textbox.
Code:-
WebForm23.aspx

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


Inherits="WebApplication2.WebForm23" %>

<!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"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<br />
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"></asp:TextBox>

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

WebForm23.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm23 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)

Shreya Kale T.21.41 Advanced Web Programming


{
SqlConnection con = new SqlConnection("data source=SQL;Initial Catalog=tyit911;user
Id=user1;Password=user1");
SqlCommand cmd = new SqlCommand(TextBox1.Text, con);
con.Open();
SqlDataReader rd = cmd.ExecuteReader();

while (rd.Read())
{
TextBox2.Text += rd[0] + " " + rd[1] + " " + rd[2] + "\n";
}

}
}
}

Output:-

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


Code:-
WebForm24.aspx

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


Inherits="WebApplication2.WebForm24" %>

<!DOCTYPE html>

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

Shreya Kale T.21.41 Advanced Web Programming


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

WebForm24.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm24 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=SQL;Initial Catalog=tyit911;user
Id=user1;Password=user1");
SqlCommand cmd = new SqlCommand("select * from Student1",con);
con.Open();
SqlDataReader rd = cmd.ExecuteReader();
GridView1.DataSource = rd;
GridView1.DataBind();
con.Close();
}
}
}

Output:-

Shreya Kale T.21.41 Advanced Web Programming


Practical 7
Working with Database
a) Create a web application to display Databinding using dropdownlist control.
Code:-
WebForm25.aspx

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


Inherits="WebApplication2.WebForm25" %>

<!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" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
</div>
</form>
</body>
</html>

WebForm25.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm25 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection("data source=SQL;Initial Catalog=tyit911;user
Id=user1;Password=user1");
SqlCommand cmd = new SqlCommand("select Id,name from Student1", con);

Shreya Kale T.21.41 Advanced Web Programming


con.Open();
SqlDataReader rd = cmd.ExecuteReader();
DropDownList1.DataSource = rd;
DropDownList1.DataTextField = "Id";
DropDownList1.DataValueField = "name";
DropDownList1.DataBind();
con.Close();
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)


{
Response.Write(DropDownList1.SelectedValue);
}
}
}

Output:-

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

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


Inherits="WebApplication2.WebForm26" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter id:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
Enter name:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
Enter class:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

Shreya Kale T.21.41 Advanced Web Programming


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

WebForm26.aspx.cs

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

namespace WebApplication2
{
public partial class WebForm26 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection("data source=SQL;Initial Catalog=tyit911;user
Id=user1;Password=user1");
SqlCommand cmd = new SqlCommand("insert into Student1 values(@Id, @name, @class)", con);
cmd.Parameters.AddWithValue("@Id", TextBox1.Text);
cmd.Parameters.AddWithValue("@name", TextBox2.Text);
cmd.Parameters.AddWithValue("@class", TextBox3.Text);
con.Open();
cmd.ExecuteNonQuery();
Response.Write("data inserted");
con.Close();

}
}
}

Output:-

Shreya Kale T.21.41 Advanced Web Programming


Practical 8
Working with data controls
b) Create a web application to demonstrate data binding using DetailsView and FormView Control
Code:-

Shreya Kale T.21.41 Advanced Web Programming


FormView Control
WebForm27.aspx

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


Inherits="WebApplication8.WebForm27" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:tyit911ConnectionString %>" SelectCommand="SELECT [Id], [Name] FROM
[sg01]"></asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="Id"
DataSourceID="SqlDataSource2">
<EditItemTemplate>
Id:
<asp:Label ID="IdLabel1" runat="server" Text='<%# Eval("Id") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
roll no:
<asp:TextBox ID="roll_noTextBox" runat="server" Text='<%# Bind("[roll no]") %>' />
<br />
class:
<asp:TextBox ID="classTextBox" runat="server" Text='<%# Bind("class") %>' />
<br />
address:
<asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
<br />
gender:
<asp:TextBox ID="genderTextBox" runat="server" Text='<%# Bind("gender") %>' />
<br />
marks:
<asp:TextBox ID="marksTextBox" runat="server" Text='<%# Bind("marks") %>' />
<br />

Shreya Kale T.21.41 Advanced Web Programming


<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
&nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Id:
<asp:TextBox ID="IdTextBox" runat="server" Text='<%# Bind("Id") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
roll no:
<asp:TextBox ID="roll_noTextBox" runat="server" Text='<%# Bind("[roll no]") %>' />
<br />
class:
<asp:TextBox ID="classTextBox" runat="server" Text='<%# Bind("class") %>' />
<br />
address:
<asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
<br />
gender:
<asp:TextBox ID="genderTextBox" runat="server" Text='<%# Bind("gender") %>' />
<br />
marks:
<asp:TextBox ID="marksTextBox" runat="server" Text='<%# Bind("marks") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Id:
<asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id") %>' />
<br />
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
<br />

roll no:
<asp:Label ID="roll_noLabel" runat="server" Text='<%# Bind("[roll no]") %>' />
<br />
class:
<asp:Label ID="classLabel" runat="server" Text='<%# Bind("class") %>' />
<br />
address:
<asp:Label ID="addressLabel" runat="server" Text='<%# Bind("address") %>' />
<br />
gender:
<asp:Label ID="genderLabel" runat="server" Text='<%# Bind("gender") %>' />

Shreya Kale T.21.41 Advanced Web Programming


<br />
marks:
<asp:Label ID="marksLabel" runat="server" Text='<%# Bind("marks") %>' />
<br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:tyit911ConnectionString %>" SelectCommand="SELECT * FROM [sg01] WHERE ([Id] =
@Id)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Id" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

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

Output:-

DetailView Control
WebForm28.aspx

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


Inherits="WebApplication21.WebForm3" %>

<!DOCTYPE html>

Shreya Kale T.21.41 Advanced Web Programming


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
GridView:<br />
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="Id" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="rollno" HeaderText="rollno" SortExpression="rollno" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:tyit911ConnectionString %>" SelectCommand="SELECT [Id], [rollno] FROM
[studentdata]"></asp:SqlDataSource>
<br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:tyit911ConnectionString %>" SelectCommand="SELECT * FROM [studentdata] WHERE
([Id] = @Id)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Id" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
DetailsView:<br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Id"
DataSourceID="SqlDataSource2" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="rollno" HeaderText="rollno" SortExpression="rollno" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="class" HeaderText="class" SortExpression="class" />
<asp:BoundField DataField="marks" HeaderText="marks" SortExpression="marks" />
<asp:BoundField DataField="subject" HeaderText="subject" SortExpression="subject" />
<asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />
</Fields>
</asp:DetailsView>
</div>
</form>
</body>
</html>

Output:-

Shreya Kale T.21.41 Advanced Web Programming


c) Create a web application to display Using Disconnected Data Access and Databinding using GridView.
Code:-
WebForm1.aspx

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


Inherits="WebApplication25.WebForm1" %>

<!DOCTYPE html>

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

WebForm1.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;

namespace WebApplication25

Shreya Kale T.21.41 Advanced Web Programming


{
public partial class WebForm4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=SQL;Initial Catalog=tyit911;user
Id=user1;password=user1");
SqlDataAdapter ad=new SqlDataAdapter("select * from std",con);
DataSet ds = new DataSet();
ad.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}
Output:-

Practical 9
Working with GridView control
b. Create a web application to demonstrate use of GridView button column and GridView
events.

Code:
WebForm2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs"
Inherits="WebApplication21.WebForm3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

Shreya Kale T.21.41 Advanced Web Programming


</head>
<body>
<form id="form1" runat="server">
<div>
GridView:<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" PageSize="2">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True"
/>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="rollno" HeaderText="rollno" SortExpression="rollno" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="class" HeaderText="class" SortExpression="class" />
<asp:BoundField DataField="marks" HeaderText="marks" SortExpression="marks" />
<asp:BoundField DataField="subject" HeaderText="subject" SortExpression="subject" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:tyit911ConnectionString %>" DeleteCommand="DELETE FROM [test] WHERE [Id] = @Id"
InsertCommand="INSERT INTO [test] ([Id], [rollno], [name], [class], [marks], [subject]) VALUES (@Id,
@rollno, @name, @class, @marks, @subject)" SelectCommand="SELECT * FROM [test]"
UpdateCommand="UPDATE [test] SET [rollno] = @rollno, [name] = @name, [class] = @class, [marks] =
@marks, [subject] = @subject WHERE [Id] = @Id">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Id" Type="Int32" />
<asp:Parameter Name="rollno" Type="String" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="class" Type="String" />
<asp:Parameter Name="marks" Type="String" />
<asp:Parameter Name="subject" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="rollno" Type="String" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="class" Type="String" />
<asp:Parameter Name="marks" Type="String" />
<asp:Parameter Name="subject" Type="String" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
FormsView:<br />
<br />
<asp:FormView ID="FormView1" runat="server" DataKeyNames="Id"
DataSourceID="SqlDataSource2">
<EditItemTemplate>
Id:

Shreya Kale T.21.41 Advanced Web Programming


<asp:Label ID="IdLabel1" runat="server" Text='<%# Eval("Id") %>' />
<br />
rollno:
<asp:TextBox ID="rollnoTextBox" runat="server" Text='<%# Bind("rollno") %>' />
<br />
name:
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
<br />
class:
<asp:TextBox ID="classTextBox" runat="server" Text='<%# Bind("class") %>' />
<br />
marks:
<asp:TextBox ID="marksTextBox" runat="server" Text='<%# Bind("marks") %>' />
<br />
subject:
<asp:TextBox ID="subjectTextBox" runat="server" Text='<%# Bind("subject") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
&nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Id:
<asp:TextBox ID="IdTextBox" runat="server" Text='<%# Bind("Id") %>' />
<br />
rollno:
<asp:TextBox ID="rollnoTextBox" runat="server" Text='<%# Bind("rollno") %>' />
<br />
name:
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
<br />
class:
<asp:TextBox ID="classTextBox" runat="server" Text='<%# Bind("class") %>' />
<br />
marks:
<asp:TextBox ID="marksTextBox" runat="server" Text='<%# Bind("marks") %>' />
<br />
subject:
<asp:TextBox ID="subjectTextBox" runat="server" Text='<%# Bind("subject") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Id:
<asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id") %>' />
<br />
rollno:

Shreya Kale T.21.41 Advanced Web Programming


<asp:Label ID="rollnoLabel" runat="server" Text='<%# Bind("rollno") %>' />
<br />
name:
<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name") %>' />
<br />
class:
<asp:Label ID="classLabel" runat="server" Text='<%# Bind("class") %>' />
<br />
marks:
<asp:Label ID="marksLabel" runat="server" Text='<%# Bind("marks") %>' />
<br />
subject:
<asp:Label ID="subjectLabel" runat="server" Text='<%# Bind("subject") %>' />
<br />

</ItemTemplate>
</asp:FormView>
</div>
<br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:tyit911ConnectionString %>" SelectCommand="SELECT * FROM [test] WHERE ([Id] =
@Id)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Id" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

Output:

Shreya Kale T.21.41 Advanced Web Programming


Shreya Kale T.21.41 Advanced Web Programming
Shreya Kale T.21.41 Advanced Web Programming
Practical 10
Working with AJAX and XML

a. Create a web application to demonstrate reading and writing operations with XML.
Code:
XMLFile1.xml
<?xml version="1.0" encoding="utf-8" ?>
<students>
<student>
<rollno>1</rollno>
<name>Sam</name>
<class>tyit</class>
</student>
<student>
<rollno>2</rollno>
<name>Rom</name>
<class>syit</class>
</student>
</students>

WebForm1.aspx

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


Inherits="WebApplication23.WebForm2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
<br />
enter name:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
enter rollno:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
enter class:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="read" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="write" OnClick="Button2_Click" />
</div>
</form>
</body>

Shreya Kale T.21.41 Advanced Web Programming


</html>

aspx.cs code:

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

namespace WebApplication23
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
XmlTextReader rd = new XmlTextReader(Server.MapPath("~/XMLFile1.xml"));
DataSet ds = new DataSet();
ds.ReadXml(rd);
GridView1.DataSource = ds;
GridView1.DataBind();

protected void Button2_Click(object sender, EventArgs e)


{
XmlTextWriter wr = new XmlTextWriter(Server.MapPath("~/f1.xml"),System.Text.Encoding.UTF8);
wr.WriteStartDocument();
wr.WriteStartElement("students");
wr.WriteStartElement("student");
wr.WriteElementString("name", TextBox1.Text);
wr.WriteElementString("rollno", TextBox2.Text);
wr.WriteElementString("class", TextBox3.Text);
wr.WriteEndElement();
wr.WriteEndElement();
wr.WriteEndDocument();
wr.Flush();
Response.Redirect("~/f1.xml");
}
}
}

Output:-

Shreya Kale T.21.41 Advanced Web Programming


b. Create a web application to demonstrate Form Security with proper Authentication and Authorization
properties.
Code:
Web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<authentication mode="Forms">
<forms loginUrl="WebForm2.aspx" defaultUrl="WebForm3.aspx" timeout="30" protection="None">
<credentials passwordFormat="Clear">
<user name="awp" password="awp@123"/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>

Webform2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="WebApplication17.WebForm2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

Shreya Kale T.21.41 Advanced Web Programming


</head>
<body>
<form id="form1" runat="server">
<div>
Enter username:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />Enter password:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Login" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>

Webform2.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.Web.Security;

namespace WebApplication17
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
if(FormsAuthentication.Authenticate(TextBox1.Text,TextBox2.Text))
{
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
}
else
{
Response.Write("Wrong credentials");
TextBox1.Text = " ";
TextBox2.Text = " ";
}
}
}
}

Webform3.aspx:

Shreya Kale T.21.41 Advanced Web Programming


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs"
Inherits="WebApplication17.WebForm3" %>

<!DOCTYPE html>

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

Output:

c. Create a web application to demonstrate use of various Ajax controls.


Code:
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication22.WebForm1" %>

<!DOCTYPE html>

Shreya Kale T.21.41 Advanced Web Programming


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
outside panel:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
Enter num1:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />Enter num2:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br /><asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
Please wait....
</ProgressTemplate>
</asp:UpdateProgress>
<br />add:<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />sub:<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />multi<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
<br />div:<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick"></asp:Timer>
<asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication22
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToLongTimeString();
}

protected void Button1_Click(object sender, EventArgs e)


{

Shreya Kale T.21.41 Advanced Web Programming


System.Threading.Thread.Sleep(2000);
int x, y;
x = Convert.ToInt32(TextBox1.Text);
y = Convert.ToInt32(TextBox2.Text);
Label2.Text=(x+y).ToString();
Label3.Text = (x-y).ToString();
Label4.Text = (x*y).ToString();
Label5.Text = (x/y).ToString();
}

protected void Timer1_Tick(object sender, EventArgs e)


{
Label6.Text = (DateTime.Now.ToLongTimeString());
}
}
}
Output:-

Practical 11
Programs to create and use DLL

ClassLibrary1:-

Shreya Kale T.21.41 Advanced Web Programming


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1
{
public class Class1
{
public double add(int x, int y)
{
return(x + y);
}
public double sub(int x, int y)
{
return (x - y);
}
public double mul(int x, int y)
{
return (x * y);
}
}
}

WebForm1.aspx:-

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


Inherits="WebApplication4.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter Number 1:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />Enter Number 2:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br /><asp:Button ID="Button1" runat="server" Text="Addition" OnClick="Button1_Click" />
<br /><asp:Button ID="Button2" runat="server" Text="Subtraction" OnClick="Button2_Click" />
<br /><asp:Button ID="Button3" runat="server" Text="Multiplication" OnClick="Button3_Click" />
<br />Solution:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

WebForm1.aspx.cs:-

Shreya Kale T.21.41 Advanced Web Programming


using ClassLibrary1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication4
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int x, y;
x=Convert.ToInt32(TextBox1.Text);
y = Convert.ToInt32(TextBox2.Text);
Class1 obj=new Class1();
Label1.Text=("Addition is "+obj.add(x,y).ToString());
}
protected void Button2_Click(object sender, EventArgs e)
{
int x, y;
x = Convert.ToInt32(TextBox1.Text);
y = Convert.ToInt32(TextBox2.Text);
Class1 obj = new Class1();
Label1.Text = ("Subtraction is "+obj.sub(x, y).ToString());
}
protected void Button3_Click(object sender, EventArgs e)
{
int x, y;
x = Convert.ToInt32(TextBox1.Text);
y = Convert.ToInt32(TextBox2.Text);
Class1 obj = new Class1();
Label1.Text = ("Multiplication is "+obj.mul(x, y).ToString());
}
}
}
Output:

Shreya Kale T.21.41 Advanced Web Programming


Shreya Kale T.21.41 Advanced Web Programming

You might also like