0% found this document useful (0 votes)
49 views57 pages

AWD Document

doc

Uploaded by

monikarnayak
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)
49 views57 pages

AWD Document

doc

Uploaded by

monikarnayak
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/ 57

ADVANCED WEB DEVELOPMENT

T.Y.B.Sc.IT (INFORMATION TECHNOLOGY)

BY

Name: Nayak Monika Ravindra

Seat Number:

N. B. MEHTA (VALWADA) SCIENCE COLLEGE, BORDI


BORDI - 401 701
MAHARASHTRA

DEPARTMENT OF INFORMATION TECHNOLOGY


T.Y.B.Sc.IT (INFORMATION TECHNOLOGY)
Semester-5

Academic year 2024-2025

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 1


N. B. MEHTA (VALWADA) SCIENCE COLLEGE, BORDI
(Affiliated to University of Mumbai)
BORDI - 401 701
MAHARASHTRA

DEPARTMENT OF INFORMATION TECHNOLOGY

CERTIFICATE

This is to certify that the work entered in this journal is the work of Shri NAYAK MONIKA
RAVINDRA of T.Y.B.Sc.IT , division Information Technology , Subject: Advanced Web
Development, Roll No. 24 Uni. Exam No_____ has satisfactorily completed the required
number of practical and worked for the terms of the Year 2024-25 in the college laboratory
as laid down by the university.

______________________ ______________________ ____________________

Head of the External Internal Examiner


Department Examiner Subject teacher

Date : / 10/ 2024

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 2


TABLE OF CONTENT
Sr.no Practical Signature
1. Write the program for the following:
a. Create an application to print on screen the output of adding,
subtracting, multiplying and dividing two numbers entered by the
user in C#.
b. Create an application to print Floyd’s triangle till n rows in C#.
c. Create an application to demonstrate following operations
i. Generate Fibonacci series. ii. Test for prime numbers.
2. Write the program for the following:
a. Create a simple application to demonstrate the concepts boxing
and unboxing.
b. Create a simple application to perform addition and subtraction
using delegate.
c. Create a simple application to demonstrate use of the concepts of
interfaces.
3. Write the program for the following:
a. Create a simple web page with various server controls to
demonstrate setting and use of their properties.
(Example : AutoPostBack)
b. Create a simple application to demonstrate your vacation using
calendar control.
c. Demonstrate the use of Treeview operations on the web form.
4. Write the program for the following:
a. Create a Registration form to demonstrate use of various
Validation controls.
b. Create Web Form to demonstrate use of Adrotator Control.
c. Create Web Form to demonstrate use User Controls.
5. Write the program for the following:
a. Create Web Form to demonstrate use of Website Navigation
control.
b. Create a web application to demonstrate use of Master Page and
content page.
c. Create a web application to demonstrate various states of
ASP.NET Pages.
6. Write the program for the following:
a. Create a web application for inserting and deleting records from a
database.
b. Create a web application to display Using Disconnected Data
Access and Databinding using GridView.
7. Write the program for the following:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 3


a. Create a web application to demonstrate the use of different
types of Cookies.
b. Create a web application to demonstrate Form Security and
Windows Security with proper Authentication and Authorization
properties.
8. Write the program for the following:
a. Create a web application for inserting and deleting records from a
database. (Using Execute Non Query).
b. Create a web application for user defined exception handling.
9. Write the program for the following:
a. Create a web application to demonstrate use of GridView button
column and GridView events along with paging and sorting.
b. Create a web application to demonstrate data binding using
DetailsView and FormView Control.

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 4


PRACTICAL No: 1
A: Create an application to print on screen the output of adding, subtracting,
multiplying and dividing two numbers entered by the user in C#.
Program1.cs
using System;

namespace Practical1_A
{
class Program1
{
static void Main(string[] args)
{
int n1, n2;

Console.Write("Enter the First Number: ");


n1 = int.Parse(Console.ReadLine());

Console.Write("Enter the Second Number: ");


n2 = int.Parse(Console.ReadLine());

Console.WriteLine("\nAddition is : " + (n1 + n2));


Console.WriteLine("Subtraction is : " + (n1 - n2));
Console.WriteLine("Multiplication is : " + (n1 * n2));
Console.WriteLine("Division is : " + (n1 / n2));

Console.ReadKey();
}
}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 5


B: Create an application to print Floyd’s triangle till n rows in C#.
Program2.cs
using System;

namespace Practical1_B
{
class Program2
{
static void Main(string[] args)
{
int row,num=1;

Console.Write("Enter the number of rows in Floyd Tringle


: ");
row = int.Parse(Console.ReadLine());

Console.Write("\n");
for (int i=1; i<=row;i++)
{
for(int j=1; j<=i;j++)
{
Console.Write(num + "\t");
num++;
}
Console.Write("\n");
}

Console.ReadKey();
}
}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 6


C: Create an application to demonstrate following operations i. Generate
Fibonacci series. ii. Test for prime numbers.
i. Generate Fibonacci series.
Program3_1.cs
using System;

namespace Practical1_C
{
class Program3
{
static void Main(string[] args)
{
int a = 0, b = 1, c,num,count=1;

Console.Write("Enter the number of Fibonacci series : ");


num = int.Parse(Console.ReadLine());

Console.Write("\nFibonacci series : ");

while (count<=num)
{
Console.Write(a +"\t");

c=a+b;
a = b;
b = c;

count++;
}
Console.ReadKey();
}
}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 7


ii. Test for prime numbers.
Program3_2.cs
using System;

namespace Practical1_C {
class Program {
static void Main(string[] args) {
int num;
Boolean prime=true;

Console.Write("Enter the Number: ");


num = int.Parse(Console.ReadLine());

int temp = num / 2;


for(int i=2;i<=temp;i++)
{
if (num % i ==0) {
Console.WriteLine("\nThe number "+ num + " is
not Prime number.");
prime = false;
break;
}
}
if (prime) {
Console.WriteLine("\nThe number " + num + " is Prime
number.");
}

Console.ReadKey();
}
}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 8


PRACTICAL No : 2
A: Create a simple application to demonstrate the concepts boxing and
unboxing.
Program1.cs
using System;

namespace Practical2_A
{
class Program1
{
static void Main(string[] args)
{
int num = 17;
object boxednum = num;

int unboxednum = (int)boxednum;

Console.WriteLine("Boxed Integer: " + boxednum);


Console.WriteLine("Unboxed Integer: " + unboxednum);

double num1 = 17.5;


object bx = num1;

double ux = (double)bx;

Console.WriteLine("\nBoxed Double Value : " + bx);


Console.WriteLine("Unboxed Double Value: " + ux);

Console.ReadKey();

}
}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 9


B: Create a simple application to perform addition and subtraction using
delegate.
Program2.cs
using System;

namespace Practical2_B
{
class Program
{
delegate float Calculater(float a, float b);
static void Main(string[] args)
{
Calculater add = Add;
Calculater sub = Sub;

Console.Write("Enter the First Number: ");


float num1 = float.Parse(Console.ReadLine());
Console.Write("Enter the Second Number: ");
float num2 = float.Parse(Console.ReadLine());

float addition = add(num1, num2);


float subtraction = sub(num1, num2);

Console.WriteLine($"\nAddition is : {addition}");
Console.WriteLine($"Subtraction is : {subtraction}");
Console.ReadKey();
}
static float Add(float a, float b)
{
return a + b;
}
static float Sub(float a, float b)
{
return a - b;
} }
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 10


C: Create a simple application to demonstrate use of the concepts of
interfaces.
Program1.cs
using System;
namespace Practical2_C
{
interface Area {
double show(double s, double t);
}
class Rect : Area
{
public double show(double s, double t) {
return s * t;
}
}
class Circle: Area
{
public double show(double s, double t) {
return (3.14 * s * s);
}
static void Main(string[] args) {
Rect r1 = new Rect();
Circle c1 = new Circle();

double rect_area = r1.show(3,4);


double circle_area = c1.show(3, 4);

Console.WriteLine($"Area of Rectangle is :
{rect_area}");
Console.WriteLine($"Area of Circle is : {circle_area}");

Console.ReadKey();
}
}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 11


PRACTICAL No : 3
A: Create a simple web page with various server controls to demonstrate
setting and use of their properties. (Example : AutoPostBack)
Practical3_A.aspx
Design:
Components: labels, textbox, radio button, dropdown list, button.
Steps: 1] right click on radio buttons -> properties -> group name = “r1”
For all radio button.
2] Click on Dropdown list and Enable AutoPostBack.

Program_3A.aspx.cs
using System;
namespace Practical_3_a
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String s;

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 12


if (RadioButton1.Checked == true)
{
s = RadioButton1.Text;
}
else if (RadioButton2.Checked == true)
{
s = RadioButton2.Text;
}
else
{
s = RadioButton3.Text;
}

Label6.Text = "You have been Enrolled in " + s;


}

protected void DropDownList1_SelectedIndexChanged


(object sender, EventArgs e)
{
Label7.Text = DropDownList1.SelectedValue;
}
}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 13


B: Create a simple application to demonstrate your vacation using calendar
control.
Practical3_B.aspx
Design:
Components: Calendar.
Steps: From toolbox select Calendar -> Properties -> Events ->
DayRender = Calander -> SelectionChanged =
Calendar1_SelectionChanged.

Practical3_B.aspx.cs
using System;

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

protected void Calendar(object sender, DayRenderEventArgs e)


{

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 14


if ((e.Day.Date >= new DateTime(2024,10,12))
&& (e.Day.Date <= new DateTime(2024, 10, 20)))
{
e.Cell.BackColor = System.Drawing.Color.AliceBlue;
e.Cell.BorderColor = System.Drawing.Color.b;

e.Cell.BorderWidth = new Unit(2);

e.Cell.Controls.Add(new LiteralControl
("<br> Study Vacation"));
}
}
}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 15


C: Demonstrate the use of Treeview operations on the web form.
Practical3_C.aspx
Design:
Components: TreeView.
Steps: Add TreeView from toolbox -> Edit Nodes -> Add Nodes.
Properties -> Events -> SelectNodeChanged =
TreeView1_SelectedNodeChanged.

Practical3_C.aspx.cs
using System;

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

protected void TreeView1_SelectedNodeChanged


(object sender, EventArgs e)
{
Response.Write("You have Selected : "

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 16


+ TreeView1.SelectedValue);
}

protected void TreeView1_TreeNodeCollapsed


(object sender, TreeNodeEventArgs e)
{
Response.Write("The value Collapsed Was : "
+ e.Node.Value);
}

}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 17


PRACTICAL No : 4
A: Create a Registration form to demonstrate use of various Validation
controls.

Practical4_A.aspx
Design:
Components: labels, textbox, button, Validaters [RequiredFieldValidator,
RangeValidator, CompareValidator, RegularExpressionValidator].
Steps: 1] in Web.config file add lines “ <addSettings> <add key =
’ValidationSettings : UnobtrusiveValidationMode‘ value=’None’/>
</appSettings> “

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

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

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 18


protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("Submitted Successfully");
}
}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 19


B: Create Web Form to demonstrate use of Adrotator Control.
Practical4_B.aspx
Design:
Components: Adrotator
Steps: 1] from toolbox select Adrotator -> Right click on project -> add->
New item -> select data -> xml file -> add .
2] click on Adrotator ->choose data source -> xml file -> your xml file.

XMLFile.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>Drone.jpg</ImageUrl>
<AlternetText>Autnomous Drone</AlternetText>
<Impressions>50</Impressions>
<Keyword>Drone</Keyword>
</Ad>
<Ad>
<ImageUrl>Car.jpg</ImageUrl>
<AlternetText>Autonomous Car</AlternetText>
<Impressions>50</Impressions>
<Keyword>Car</Keyword>
</Ad>

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 20


</Advertisements>

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 21


C: Create Web Form to demonstrate use User Controls
Components: labels, textbox.
Steps: 1] right click on project -> add -> new items -> web from user control
-> add .
Practical4_C.aspx
Design:

usercontrol.aspx

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 22


Practical4_C.aspx
Source code:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="Practical_4C.WebForm1" %>
<%@ Register src="~/WebUserControl1.ascx" TagName="WebUserControl"
TagPrefix="uc1" %>
<!DOCTYPE html>

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

<br />
<asp:Label ID="Label1" runat="server"
Text="Enter Name :"></asp:Label>
&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1"
runat="server" OnClick="Button1_Click"
style="height: 35px" Text="Submit" />
<br />
<br />
<asp:Label ID="Label2" runat="server"></asp:Label>
<br />
<br />
<uc1:WebUserControl runat="server" id="WebUserControl1"/>
</form>
</body>
</html>

Practical4_C.aspx.cs
using System;

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

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 23


protected void Button1_Click(object sender, EventArgs e)
{
Label2.Text = "Welcome " + TextBox1.Text;
}
}
}

usercontrol_C.aspx.cs
using System;

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

protected void Button1_Click(object sender, EventArgs e)


{
Label2.Text = "Hello " + TextBox1.Text;
}
}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 24


PRACTICAL No : 5
A: Create Web Form to demonstrate use of Website Navigation control.
Practical5_A.aspx
Design:
Components: Menu.
Steps: 1] From toolbox select Menu-> Edit menu items -> Add Items.
2] Create two more web pages.
3] Give specific NavigateUrl of web pages to each items.

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 25


Project_page.aspx
Design:

Help_page.aspx
Design:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 26


Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 27


B: Create a web application to demonstrate use of Master Page and content
page.
Site1.Master
Design:
Components : label ,button.
Steps:- 1] Right click on project -> add ->new item -> Master Page.
2] In ContentPlaceHolder add label & button.
3] add MasterPageFile=”~/Site1.Master” in WebForm1

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 28


Webform1.aspx
Design:

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 29


C: Create a web application to demonstrate various states of ASP.NET Pages.
Practical5_C.aspx
Design:
Components: labels, button ,Textbox, HiddenField.
Steps: 1] Click on HiddenField -> properties -> value=0
2] Add one more web page.

Webform2.aspx

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 30


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

namespace WebApplication7
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if(ViewState["count"] != null)
{
int ViewstateVal = Convert.ToInt32
(ViewState["count"]) + 1;

Label2.Text = "View State: " +


ViewstateVal.ToString();
ViewState["count"] = ViewstateVal.ToString();
}

else
{
ViewState["count"] = "1";
}
}
}

protected void Button1_Click1(object sender, EventArgs e)


{
Label1.Text = ViewState["count"].ToString();
}

protected void Button2_Click1(object sender, EventArgs e)


{
if (hf.Value != null)
{
int val = Convert.ToInt32(hf.Value) + 1;
hf.Value = val.ToString();
}
}

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 31


protected void Button3_Click(object sender, EventArgs e)
{
HttpCookie h = new HttpCookie("name");

h.Value = TextBox1.Text;
Response.Cookies.Add(h);
Response.Redirect("WebForm2.aspx");
}

}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 32


PRACTICAL No : 6
A: Create a web application for inserting and deleting records from a
database.
Components: detailsView, SqlDataSource
Steps: 1] click on view -> click on server Explorer -> right click on
data connection -> add connection -> database file name = “tyit”
-> test connection -> ok -> ok.
2] Expand tyit database -> right click on Tables -> add new table ->
Add column in table -> give table name -> click on upload ->
Update database.
3] Expand Tables -> right click on table_name -> click on show table
data -> insert values in table.
4] click on SqlDataSource -> Configure datasource -> new connection
-> database name -> copy connection string -> next ->Select table
-> Advanced -> check on both options -> ok -> next -> Test Query
-> Finish.
5] click on detailsView -> choose data source =sqlDataSource1 ->
Checked the options Enable paging, Inserting, Deleting.

Database:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 33


Practical6_A.aspx
Design:

Output:

Insert data:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 34


After inserting data:

Delete data:

After deleting data:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 35


B: Create a web application to display Using Disconnected Data Access and
Databinding using GridView.
Components: GridView, button
Steps: 1] Open SSMS -> connect to server ‘server name’ = “your server name”
->Authentication = Windows Authentication -> connect .
2] Right click on database -> new database -> database name =
“your database name” -> ok.
3] Expand database -> right click on Tables -> new -> table ->
Add columns in table -> right click on any column name ->
Set primary key to one of the column -> Save -> give table name->
Ok.
4] Expand Tables -> right click on your table ->Edit top 200 rows ->
Insert values in table.

Database:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 36


Practical6_B.aspx
Design:

Practical6_B.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
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection("Data Source=DESKTOP-
AV1M30G \\SQLEXPRESS;Initial Catalog=tyit;Integrated
Security=True");

DataSet ds = new DataSet();

SqlDataAdapter da;
protected void Page_Load(object sender, EventArgs e)
{

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 37


}

protected void Button1_Click(object sender, EventArgs e)


{
da = new SqlDataAdapter("Select * from Student;", cn);
da.Fill(ds, "Student");

GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 38


PRACTICAL No : 7
A: Create a web application to demonstrate the use of different types of
Cookies.
Components: Labels, checkbox, button.
Practical7_A.aspx
Design:

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

namespace WebApplication12
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie c1 = new HttpCookie("creater");

c1.Value = "N.B.MEHTA COLLAGE BORDI ";

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 39


Response.Cookies.Add(c1);

String author = Response.Cookies["creater"].Value;

Label1.Text=author;

Response.Cookies["comp"].Expires =
DateTime.Now.AddDays(-1);

protected void Button1_Click(object sender, EventArgs e)


{
if (CheckBox1.Checked == true)
{
Response.Cookies["comp"]["Dell"] = "Dell";
}

if (CheckBox2.Checked == true)
{
Response.Cookies["comp"]["Apple"] = "Apple";
}

if (CheckBox3.Checked == true)
{
Response.Cookies["comp"]["Lenevo"] = "Lenevo";
}

if (CheckBox4.Checked == true)
{
Response.Cookies["comp"]["Acer"] = "Acer";
}

if(Request.Cookies["comp"].Values.ToString() != null)
{
if(Request.Cookies["comp"]["Dell"] != null)
{
Label3.Text += Request.Cookies["comp"]
["Dell"] + " " ;
}

if (Request.Cookies["comp"]["Apple"] != null)
{
Label3.Text += Request.Cookies["comp"]
["Apple"] + " ";
}

if (Request.Cookies["comp"]["Lenevo"] != null)

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 40


{
Label3.Text += Request.Cookies["comp"]
["Lenevo"] + " ";
}

if (Request.Cookies["comp"]["Acer"] != null)
{
Label3.Text += Request.Cookies["comp"]
["Acer"] + " ";
}
}

else
{
Label3.Text = "Please Select Company";
}
Response.Cookies["comp"].Expires =
DateTime.Now.AddDays(-1);
}
}
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 41


B: Create a web application to demonstrate Form Security and Windows
Security with proper Authentication and Authorization properties.
Components: Labels, textbox, button, checkbox.
Practical7_B.aspx
Design:

WebForm2.aspx
Design:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 42


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

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

protected bool authenticate(String uname, String pass)


{
if (uname == "Harsh")
{
if (pass== "harsh17")
{
return true;
}
}

if (uname == "Ram")
{
if (pass == "ram123")
{
return true;
}
}

return false;

}
protected void Button1_Click(object sender, EventArgs e)
{
if (authenticate(TextBox1.Text,TextBox2.Text))
{
FormsAuthentication.RedirectFromLoginPage(
TextBox1.Text, CheckBox1.Checked);

Session["Username"] = TextBox1.Text;
Response.Redirect("Webform2.aspx");

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 43


}

else
{
Response.Write("Invalid UserName or Password.");
}
}
}
}

Output:
If User is vaild:

If User is Invaild:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 44


PRACTICAL No : 8
A: Create a web application for inserting and deleting records from a
database. (Using Execute Non Query).
Components: Labels, textbox, button, SqlDataSource , GridView.
Steps: 1] Open SSMS -> connect to server ‘server name’ = “your server name”
->Authentication = Windows Authentication -> connect .
2] Right click on database -> new database -> database name =
“your database name” -> ok.
3] Expand database -> right click on Tables -> new -> table ->
Add columns in table -> right click on any column name ->
Set primary key to one of the column -> Save -> give table name
-> ok.
4] Expand Tables -> right click on your table ->Edit top 200 rows ->
Insert values in table.
5] click on SqlDataSource -> Configure datasource -> new connection
-> change datasource to “Microsoft SQL Server (SqlClient)”
->Give Server name -> database name -> copy connection string
-> next ->Select table -> Advanced -> check on both options -> ok
-> next -> Test Query -> Finish.
6] click on gridView -> choose data source =sqlDataSource1 ->
Checked the options Enable paging.

Database:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 45


Practical8_A.aspx
Design:

Practical8_A.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 Practical_8A
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection("Data Source=DESKTOP-
AV1M30G \\SQLEXPRESS;Initial Catalog=tyit;Integrated
Security=True");
SqlCommand co = new SqlCommand();
SqlDataReader ds;
SqlParameter @p1, @p2, @p3, @p4;

protected void Page_Load(object sender, EventArgs e)


{
cn.Open();

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 46


co.Connection = cn;
}
protected void Button1_Click(object sender, EventArgs e)
{
@p1 = new SqlParameter();
@p1.ParameterName = "ID";
@p1.SqlDbType = System.Data.SqlDbType.Int;

@p2 = new SqlParameter();


@p2.ParameterName = "Name";
@p2.SqlDbType = System.Data.SqlDbType.VarChar;

@p3 = new SqlParameter();


@p3.ParameterName = "Age";
@p3.SqlDbType = System.Data.SqlDbType.Int;

@p4 = new SqlParameter();


@p4.ParameterName = "City";
@p4.SqlDbType = System.Data.SqlDbType.VarChar;

co.Parameters.AddWithValue("@p1",TextBox1.Text);
co.Parameters.AddWithValue("@p2", TextBox2.Text);
co.Parameters.AddWithValue("@p3", TextBox3.Text);
co.Parameters.AddWithValue("@p4", TextBox4.Text);

co.CommandText = "Insert into Student


(Id,Name,Age,City) Values(@p1,@p2,@p3,@p4);";
co.ExecuteNonQuery();

TextBox1.Text = null;
TextBox2.Text = null;
TextBox3.Text = null;
TextBox4.Text = null;
}
protected void Button2_Click(object sender, EventArgs e)
{
co.CommandText = "delete from Student where Id='"
+ TextBox1.Text +"';";
co.ExecuteNonQuery();
TextBox1.Text = null;
TextBox2.Text = null;
TextBox3.Text = null;
TextBox4.Text = null;

}
protected void Button3_Click(object sender, EventArgs e)
{
co.CommandText = "Select * from Student;";

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 47


ds = co.ExecuteReader();
GridView1.DataBind();
TextBox1.Text = null;
TextBox2.Text = null;
TextBox3.Text = null;
TextBox4.Text = null;

}
}
}

Output:
Insert:

After inserting data:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 48


Delete:

After deleting data:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 49


B: Create a web application for user defined exception handling.
Components: Labels.
Practical8_B.aspx
Design:

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

namespace WebApplication24
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
throw new UserDefinedException
("New User Defined Exception");
}
catch (Exception ex)

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 50


{
Label1.Text = "Exception caught here"
+ ex.ToString();
}
Label2.Text = "Final Statement that is executed";

class UserDefinedException : Exception


{
public UserDefinedException(string str)
{
Console.WriteLine("User Defined Exception");
}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 51


PRACTICAL No : 9
A: Create a web application to demonstrate use of GridView button column
and GridView events along with paging and sorting.
Components: SqlDataSource , GridView.
Steps: 1] Create one table in SSMS
2] form toolbox select SqlDataSource and GridView
3] click on SqlDataSource -> Configure datasource -> new connection
-> change datasource to “Microsoft SQL Server (SqlClient)”
->Give Server name -> database name -> copy connection string
-> next ->Select table -> Advanced -> check on both options -> ok
-> next -> Test Query -> Finish.
4] click on gridView -> choose data source =sqlDataSource1 ->
Checked the options Enable paging & sorting.
5] click on GridView -> Edit columns -> in Available fields select button
field -> click on add -> button text = “Show” -> CommandName=
“b1” -> ok .

Practical9_A.aspx
Design:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 52


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

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

protected void GridView1_RowCommand


(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName =="b1")
{
GridView1.Rows[Convert.ToInt16(e.CommandArgument)]
.BackColor =System.Drawing.Color.Red;

}
}
}

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 53


}

Output:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 54


B: Create a web application to demonstrate data binding using DetailsView
and FormView Control.
Components: Labels, SqlDataSource , DetailsView, FormView.
Steps: 1] Create two tables in SSMS
2] form toolbox select two SqlDataSource and DetailsView and
FormView
3] click on SqlDataSource -> Configure datasource -> new connection
-> change datasource to “Microsoft SQL Server (SqlClient)”
->Give Server name -> database name -> copy connection string
-> next ->Select table -> Advanced -> check on both options -> ok
-> next -> Test Query -> Finish.
4] click on detailsView -> choose data source =sqlDataSource1 ->
Checked the options Enable paging.
5] repert step 3 & 4 for FormView. Select new table for FormView
and use choose data source = sqlDataSource2 .
Practical3_C.aspx
Design:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 55


Output:

Insert:

After inserting data:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 56


Delete:
After deleting data:

Update:

After updating data:

TYBSc(Information Technology) :- Nayak Monika Ravindra pg. 57

You might also like