0% found this document useful (0 votes)
3 views55 pages

Practical-1: Department of Computer Science and Applications

The document outlines a series of practical exercises in ASP.NET, detailing the creation of web applications with various functionalities such as displaying items with images and costs, calculating totals based on user input, performing arithmetic operations, and connecting to a SQL Server database. Each practical includes a specific aim, procedure, and code snippets for implementation. The exercises progress from basic controls to database interactions, demonstrating a comprehensive approach to learning ASP.NET development.
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)
3 views55 pages

Practical-1: Department of Computer Science and Applications

The document outlines a series of practical exercises in ASP.NET, detailing the creation of web applications with various functionalities such as displaying items with images and costs, calculating totals based on user input, performing arithmetic operations, and connecting to a SQL Server database. Each practical includes a specific aim, procedure, and code snippets for implementation. The exercises progress from basic controls to database interactions, demonstrating a comprehensive approach to learning ASP.NET development.
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

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS

PRACTICAL-1

Aim- To create a web application containing the following controls:

 ListBox
 Button
 Image
 Label

Procedure-
 Open Visual Studio

 Create new [Link] Web Application

 Add a Web Form ([Link])

 Drag and drop controls:

 ListBox
 Button
 Image
 Label

 Run the application

Code-

[Link]

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"


Inherits="[Link]" %>

<!DOCTYPE html>

<html>

<body>

<form runat="server">

<asp:ListBox ID="lstItems" runat="server" AutoPostBack="true"

OnSelectedIndexChanged="lstItems_SelectedIndexChanged">

Bhumika wadhwa 1
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
<asp:ListItem Value="apple">Apple - $1.00</asp:ListItem>

<asp:ListItem Value="banana">Banana - $0.50</asp:ListItem>

<asp:ListItem Value="mango">Mango - $1.50</asp:ListItem>

<asp:ListItem Value="grape">Grape - $2.00</asp:ListItem>

</asp:ListBox>

<br /><br />

<asp:Image ID="imgItem" runat="server" Width="150px" />

<br /><br />

<asp:Button ID="btnShowCost" runat="server" Text="Show Cost"

OnClick="btnShowCost_Click" />

<br /><br />

<asp:Label ID="lblCost" runat="server"></asp:Label>

</form>

</body>

</html>

[Link]

using System;

using [Link];

namespace Practical1

public partial class Default : [Link]

Dictionary<string, decimal> prices = new Dictionary<string, decimal>()

Bhumika wadhwa 2
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
{

{"apple", 1.00m},

{"banana", 0.50m},

{"mango", 1.50m},

{"grape", 2.00m}

};

Dictionary<string, string> images = new Dictionary<string, string>()

{"apple", "[Link]

{"banana", "[Link]

{"mango", "[Link]

{"grape", "[Link]

};

protected void lstItems_SelectedIndexChanged(object sender, EventArgs e)

string selected = [Link];

[Link] = images[selected];

protected void btnShowCost_Click(object sender, EventArgs e)

string selected = [Link];

[Link] = "Cost: $" + prices[selected];

Bhumika wadhwa 3
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
}

Output-

Bhumika wadhwa 4
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-2

Aim- To display image and cost of selected item using ListBox, Image, Button and Label.

Procedure-

 Add items in ListBox


 Enable AutoPostBack
 Write code for image display
 Write code for cost display
 Run the application

Code-

[Link]

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"


Inherits="[Link]" %>

<!DOCTYPE html>

<html>

<body>

<form runat="server">

<asp:ListBox ID="lstItems" runat="server" AutoPostBack="true"

OnSelectedIndexChanged="lstItems_SelectedIndexChanged">

<asp:ListItem Value="apple">Apple - $1.00</asp:ListItem>

<asp:ListItem Value="banana">Banana - $0.50</asp:ListItem>

<asp:ListItem Value="mango">Mango - $1.50</asp:ListItem>

<asp:ListItem Value="grape">Grape - $2.00</asp:ListItem>

</asp:ListBox>

<br /><br />

<asp:Image ID="imgItem" runat="server" Width="150px" />

Bhumika wadhwa 5
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
<br /><br />

<asp:Button ID="btnShowCost" runat="server" Text="Show Cost"

OnClick="btnShowCost_Click" />

<br /><br />

<asp:Label ID="lblCost" runat="server"></asp:Label>

</form>

</body>

</html>

[Link]

using System;

using [Link];

namespace Practical1

public partial class Default : [Link]

Dictionary<string, decimal> prices = new Dictionary<string, decimal>()

{"apple", 1.00m},

{"banana", 0.50m},

{"mango", 1.50m},

{"grape", 2.00m}

};

Bhumika wadhwa 6
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
Dictionary<string, string> images = new Dictionary<string, string>()

{"apple", "[Link]

{"banana", "[Link]

{"mango", "[Link]

{"grape", "[Link]

};

protected void lstItems_SelectedIndexChanged(object sender, EventArgs e)

string selected = [Link];

[Link] = images[selected];

protected void btnShowCost_Click(object sender, EventArgs e)

string selected = [Link];

[Link] = "Cost: $" + prices[selected];

Output-

Bhumika wadhwa 7
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS

Bhumika wadhwa 8
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-3

Aim- To create a web application that calculates total cost based on quantity entered by the
user.

Procedure-

1. Open Visual Studio


2. Create [Link] Web Application
3. Add a Web Form ([Link])
4. Add controls:
o Label (Item Name / Price)
o TextBox (Quantity)
o Button (Calculate)
o Label (Result)
5. Write code for button click
6. Run the application

Code-

[Link]

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"


Inherits="[Link]" %>

<!DOCTYPE html>

<html>

<body>

<form runat="server">

Item: Apple ($2 per item)

<br /><br />

Enter Quantity:

<asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox>

<br /><br />

<asp:Button ID="btnCalculate" runat="server" Text="Calculate Total"

Bhumika wadhwa 9
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
OnClick="btnCalculate_Click" />

<br /><br />

<asp:Label ID="lblTotal" runat="server"></asp:Label>

</form>

</body>

</html>

[Link]

using System;

namespace Practical3

public partial class Default : [Link]

protected void btnCalculate_Click(object sender, EventArgs e)

int quantity = Convert.ToInt32([Link]);

int price = 2;

int total = quantity * price;

[Link] = "Total Cost: $" + total;

Output-

Bhumika wadhwa 10
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS

Bhumika wadhwa 11
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-4

Aim- To create a web application that performs basic arithmetic operations using [Link]
controls.

Procedure-

 Open Visual Studio

 Create [Link] Web Application

 Add Web Form ([Link])

 Add controls:

 2 TextBox (for numbers)


 4 Buttons (Add, Subtract, Multiply, Divide)
 Label (for result)

 Write code for button click events

 Run the application

Code-

[Link]

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"


Inherits="[Link]" %>

<!DOCTYPE html>

<html>

<body>

<form runat="server">

Enter First Number:

<asp:TextBox ID="txtNum1" runat="server"></asp:TextBox>

<br /><br />

Enter Second Number:

Bhumika wadhwa 12
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
<asp:TextBox ID="txtNum2" runat="server"></asp:TextBox>

<br /><br />

<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />

<asp:Button ID="btnSub" runat="server" Text="Subtract" OnClick="btnSub_Click" />

<asp:Button ID="btnMul" runat="server" Text="Multiply" OnClick="btnMul_Click" />

<asp:Button ID="btnDiv" runat="server" Text="Divide" OnClick="btnDiv_Click" />

<br /><br />

<asp:Label ID="lblResult" runat="server"></asp:Label>

</form>

</body>

</html>

[Link]

using System;

namespace Practical4

public partial class Default : [Link]

protected void btnAdd_Click(object sender, EventArgs e)

int a = Convert.ToInt32([Link]);

int b = Convert.ToInt32([Link]);

[Link] = "Result: " + (a + b);

Bhumika wadhwa 13
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
protected void btnSub_Click(object sender, EventArgs e)

int a = Convert.ToInt32([Link]);

int b = Convert.ToInt32([Link]);

[Link] = "Result: " + (a - b);

protected void btnMul_Click(object sender, EventArgs e)

int a = Convert.ToInt32([Link]);

int b = Convert.ToInt32([Link]);

[Link] = "Result: " + (a * b);

protected void btnDiv_Click(object sender, EventArgs e)

int a = Convert.ToInt32([Link]);

int b = Convert.ToInt32([Link]);

if (b != 0)

[Link] = "Result: " + (a / b);

else

[Link] = "Cannot divide by zero!";

Bhumika wadhwa 14
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
Output-

Bhumika wadhwa 15
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-5

Aim- To create a web application that connects to SQL Server database and displays data using
[Link].

Procedure-

 Open Visual Studio


 Create [Link] Web Application
 Open SQL Server
 Create database and table
 Add data in table
 Add GridView control in [Link]
 Write connection code in C#
 Run the application

Code-
[Link]

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"


Inherits="Practical5.Default5" %>
<html>
<body>
<form id="form1" runat="server">
<h2>Database Connection Test</h2>
<asp:Label ID="lblStatus" runat="server" Font-Size="Large" />

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

[Link]

using System;

using [Link];

using [Link];

namespace Practical5

public partial class Default5 : Page

Bhumika wadhwa 16
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
{

protected void Page_Load(object sender, EventArgs e)

string connStr = @"Data Source=.\SQLEXPRESS;Initial Catalog=master;Integrated


Security=True";

try

using (SqlConnection conn = new SqlConnection(connStr))

[Link]();

[Link] = [Link];

[Link] = "Connection has been established";

catch (Exception ex)

[Link] = [Link];

[Link] = "Connection failed: " + [Link];

Bhumika wadhwa 17
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
Output-

Bhumika wadhwa 18
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-6

Aim- To insert data into SQL Server database using [Link].

Procedure-

 Open Visual Studio


 Create [Link] Web Application
 Add Web Form ([Link])
 Create database and table in SQL Server
 Add TextBox and Button controls
 Write insert query in Button Click event
 Run the application

Code-

[Link]

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"


Inherits="Practical6.Default6" %>

<html>

<body>

<form id="form1" runat="server">

<h2>Insert Student Record</h2>

Name:

<asp:TextBox ID="txtName" runat="server" /><br /><br />

Age:

<asp:TextBox ID="txtAge" runat="server" /><br /><br />

<asp:Button ID="btnInsert" runat="server" Text="Insert" OnClick="btnInsert_Click" /><br


/><br />

<asp:Label ID="lblMsg" runat="server" />

</form>

</body>

Bhumika wadhwa 19
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
</html>

[Link]

using System;

using [Link];

using [Link];

namespace Practical6

public partial class Default6 : Page

protected void btnInsert_Click(object sender, EventArgs e)

string connStr = @"Data Source=localhost\SQLEXPRESS;Initial


Catalog=StudentDB;Integrated Security=True";

using (SqlConnection conn = new SqlConnection(connStr))

string query = "INSERT INTO Student (Name, Age) VALUES (@Name, @Age)";

SqlCommand cmd = new SqlCommand(query, conn);

[Link]("@Name", [Link]);

[Link]("@Age", [Link]);

[Link]();

[Link]();

[Link] = "Record Inserted Successfully!";

Bhumika wadhwa 20
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
}

Output-

Bhumika wadhwa 21
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-7

Aim- To display customer records from SQL Server database in [Link] using GridView.

Procedure-

1. Open Visual Studio


2. Create new [Link] Web Application (.NET Framework)
3. Select Empty Template and check Web Forms
4. Add a new Web Form → [Link]
5. Add GridView control in the form
6. Write connection string for SQL Server
7. Create database and table if not exists
8. Insert sample records
9. Fetch data using SqlDataAdapter
10. Bind data to GridView
11. Run the project

Code-

[Link]

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"


Inherits="Practical7.Default7" %>

<html><body>

<form id="form1" runat="server">

<h2>Customer Records</h2>

<asp:GridView ID="gvCustomers" runat="server"

AutoGenerateColumns="true"

BorderColor="#003366" BorderWidth="1px"

HeaderStyle-BackColor="#003366" HeaderStyle-ForeColor="White"

RowStyle-BackColor="#f0f4ff"

AlternatingRowStyle-BackColor="#dce8ff" />

</form>

Bhumika wadhwa 22
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
</body></html>

[Link]

using System;

using [Link];

using [Link];

using [Link];

namespace Practical7

public partial class Default7 : Page

string connStr = @"Data Source=.\SQLEXPRESS;Initial Catalog=EmpDB;Integrated


Security=True";

protected void Page_Load(object sender, EventArgs e)

if (!IsPostBack)

CreateAndPopulateTable();

LoadGrid();

void CreateAndPopulateTable()

using (SqlConnection conn = new SqlConnection(connStr))

Bhumika wadhwa 23
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
[Link]();

string sql = @"IF NOT EXISTS (SELECT * FROM sysobjects WHERE


name='Customer')

BEGIN

CREATE TABLE Customer (CustomerID INT, CustomerName VARCHAR(50))

INSERT INTO Customer VALUES


(121,'Baskar'),(122,'Partha'),(123,'Suresh'),(124,'Vidya')

END";

new SqlCommand(sql, conn).ExecuteNonQuery();

void LoadGrid()

using (SqlConnection conn = new SqlConnection(connStr))

[Link]();

SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Customer", conn);

DataTable dt = new DataTable();

[Link](dt);

[Link] = dt;

[Link]();

Bhumika wadhwa 24
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
}

Output-

Bhumika wadhwa 25
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-8

Aim- To create a user control that accepts username and password and validates the user.

Procedure-

 Open Microsoft Visual Studio and create a new [Link] Web Application.
 Add a User Control → [Link].
 Design the user interface with:

 TextBox for Username


 TextBox for Password
 Button for Login
 Label for displaying result

 Write validation logic in code-behind:

 If username = BCAV and password = [Link] → authorized


 Otherwise → not authorized

 Add a new Web Form → [Link].


 Register the user control in the Web Form.
 Place the user control on the page.
 Run the application.
 Enter username and password to check validation.

Code-

[Link]

<%@ Control Language="C#" AutoEventWireup="true"

CodeBehind="[Link]" Inherits="[Link]" %>

<div style="border:1px solid #003366; padding:20px; width:300px; border-radius:8px;">

<h3>User Login</h3>

<asp:Label runat="server" Text="Username:" />

<asp:TextBox ID="txtUser" runat="server" /><br /><br />

<asp:Label runat="server" Text="Password:" />

Bhumika wadhwa 26
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
<asp:TextBox ID="txtPass" runat="server" TextMode="Password" /><br /><br />

<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" />

<br /><br />

<asp:Label ID="lblMsg" runat="server" Font-Bold="true" />

</div>

[Link]

using System;

using [Link];

namespace Practical8

public partial class LoginControl : UserControl

protected void btnLogin_Click(object sender, EventArgs e)

if ([Link] == "BCAV" && [Link] == "[Link]")

[Link] = [Link];

[Link] = "✅ User is authorized!";

else

[Link] = [Link];

[Link] = "❌ User is NOT authorized!";

Bhumika wadhwa 27
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
}

[Link]

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"


Inherits="Practical8.Default8" %>

<%@ Register Src="~/[Link]" TagName="Login" TagPrefix="uc" %>

<!DOCTYPE html>

<html>

<body>

<form id="form1" runat="server">

<h2>Practical 8: Login User Control</h2>

<uc:Login ID="LoginCtrl" runat="server" />

</form>

</body>

</html>

Output-

Bhumika wadhwa 28
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS

Bhumika wadhwa 29
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-9

Aim- To perform database operations (Insert, Update, Delete) using [Link] and [Link].

Procedure-

1. Open Visual Studio.


2. Create a new [Link] Web Forms Application.
3. Create a database in SQL Server.
4. Create a table with the following fields:
o DeptId
o DeptName
o EmpName
o Salary
5. Open [Link] and add the following controls:
o Four TextBoxes
o Three Buttons (Insert, Update, Delete)
o One Label
6. Write the connection string in the code-behind file.
7. Write code for:
o Insert operation
o Update operation (increase salary by 15%)
o Delete operation
8. Run the application and verify the output.

Code-

[Link]

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"


Inherits="Practical9.Default9" %>

<html><body>

<form id="form1" runat="server">

<h2>Employee DB — Insert / Update / Delete</h2>

<table>

<tr><td>DeptId:</td><td><asp:TextBox ID="txtDeptId" runat="server" /></td></tr>

<tr><td>DeptName:</td><td><asp:TextBox ID="txtDeptName" runat="server"


/></td></tr>

Bhumika wadhwa 30
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
<tr><td>EmpName:</td><td><asp:TextBox ID="txtEmpName" runat="server" /></td></tr>

<tr><td>Salary:</td><td><asp:TextBox ID="txtSalary" runat="server" /></td></tr>

</table>

<asp:Button ID="btnInsert" runat="server" Text="Insert" OnClick="btnInsert_Click" />

<asp:Button ID="btnUpdate" runat="server" Text="Update Salary+15%"


OnClick="btnUpdate_Click" />

<asp:Button ID="btnDelete" runat="server" Text="Delete Last Row"


OnClick="btnDelete_Click" />

<asp:Button ID="btnShow" runat="server" Text="Show Records" OnClick="btnShow_Click"


/>

<br /><br />

<asp:Label ID="lblMsg" runat="server" ForeColor="Green" />

<br />

<asp:GridView ID="gvEmp" runat="server" AutoGenerateColumns="true"

HeaderStyle-BackColor="#003366" HeaderStyle-ForeColor="White" />

</form>

</body></html>

[Link]

using System;

using [Link];

using [Link];

using [Link];

namespace Practical9

public partial class Default9 : Page

Bhumika wadhwa 31
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
{

string connStr = @"Data Source=.\SQLEXPRESS;Initial Catalog=EmpDB;Integrated


Security=True";

protected void Page_Load(object sender, EventArgs e)

if (!IsPostBack) SetupTable();

void SetupTable()

using (SqlConnection conn = new SqlConnection(connStr))

[Link]();

string sql = @"IF NOT EXISTS (SELECT * FROM sysobjects WHERE


name='EmpDept')

CREATE TABLE EmpDept (

DeptId INT IDENTITY(1,1) PRIMARY KEY,

DeptName VARCHAR(50),

EmpName VARCHAR(50),

Salary DECIMAL(10,2))";

new SqlCommand(sql, conn).ExecuteNonQuery();

protected void btnInsert_Click(object sender, EventArgs e)

Bhumika wadhwa 32
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
using (SqlConnection conn = new SqlConnection(connStr))

[Link]();

string sql = "INSERT INTO EmpDept(DeptName,EmpName,Salary)


VALUES(@d,@n,@s)";

SqlCommand cmd = new SqlCommand(sql, conn);

[Link]("@d", [Link]);

[Link]("@n", [Link]);

[Link]("@s", [Link]([Link]));

[Link]();

[Link] = "Record inserted!";

protected void btnUpdate_Click(object sender, EventArgs e)

using (SqlConnection conn = new SqlConnection(connStr))

[Link]();

string sql = "UPDATE EmpDept SET Salary = Salary * 1.15 WHERE


EmpName=@n";

SqlCommand cmd = new SqlCommand(sql, conn);

[Link]("@n", [Link]);

int rows = [Link]();

[Link] = rows > 0 ? "Salary updated!" : "No record found!";

Bhumika wadhwa 33
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
}

protected void btnDelete_Click(object sender, EventArgs e)

using (SqlConnection conn = new SqlConnection(connStr))

[Link]();

string sql = "DELETE TOP(1) FROM EmpDept";

new SqlCommand(sql, conn).ExecuteNonQuery();

[Link] = "First row deleted!";

protected void btnShow_Click(object sender, EventArgs e)

using (SqlConnection conn = new SqlConnection(connStr))

[Link]();

DataTable dt = new DataTable();

new SqlDataAdapter("SELECT * FROM EmpDept", conn).Fill(dt);

[Link] = dt;

[Link]();

[Link] = "";

Bhumika wadhwa 34
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
}

Output-

Bhumika wadhwa 35
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-10

Aim- To create an [Link] Web application to accept user details such as name, password,
age, email id, and user id with proper validations.

Procedure-

1. Create a new [Link] Web Forms application.


2. Add a Web Form.
3. Place TextBox controls for Name, Password, Confirm Password, Age, Email ID, and
User ID.
4. Add validation controls:
o RequiredFieldValidator for compulsory fields
o CompareValidator for password confirmation
o RangeValidator for age (21–30)
o RegularExpressionValidator for email and user id
5. Add a Button control for submission.
6. Run the application and verify validations.

Code-

[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="Practical10.Default10" %>

<html><body>

<form id="form1" runat="server">

<h2>Registration Form</h2>

Name: <asp:TextBox ID="txtName" runat="server" />

<asp:RequiredFieldValidator ControlToValidate="txtName" runat="server"

ErrorMessage="Name is required." ForeColor="Red" /><br />

Password: <asp:TextBox ID="txtPwd" runat="server" TextMode="Password" />

<asp:RequiredFieldValidator ControlToValidate="txtPwd" runat="server"

ErrorMessage="Password required." ForeColor="Red" /><br />

Confirm Pwd: <asp:TextBox ID="txtPwd2" runat="server" TextMode="Password" />

Bhumika wadhwa 36
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
<asp:CompareValidator runat="server" ControlToValidate="txtPwd2"

ControlToCompare="txtPwd" ErrorMessage="Passwords do not match." ForeColor="Red"


/><br />

Age (21-30): <asp:TextBox ID="txtAge" runat="server" />

<asp:RangeValidator runat="server" ControlToValidate="txtAge"

MinimumValue="21" MaximumValue="30" Type="Integer"

ErrorMessage="Age must be 21-30." ForeColor="Red" /><br />

Email: <asp:TextBox ID="txtEmail" runat="server" />

<asp:RegularExpressionValidator runat="server" ControlToValidate="txtEmail"

ValidationExpression="^[\w\.-]+@[\w\.-]+\.\w{2,}$"

ErrorMessage="Enter a valid email." ForeColor="Red" /><br />

User ID: <asp:TextBox ID="txtUID" runat="server" />

<asp:RegularExpressionValidator runat="server" ControlToValidate="txtUID"

ValidationExpression="^(?=.*[A-Z])(?=.*\d).{7,20}$"

ErrorMessage="UserID: 7-20 chars, must have a capital & digit." ForeColor="Red" /><br
/>

[Link]

using System;

using [Link];

namespace Practical10

public partial class Default10 : Page

protected void btnReg_Click(object sender, EventArgs e)

Bhumika wadhwa 37
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
{

if ([Link])

[Link] = $"✅ Registration successful! Welcome, {[Link]}";

<asp:Button ID="btnReg" runat="server" Text="Register" OnClick="btnReg_Click" />

<br />

<asp:Label ID="lblResult" runat="server" ForeColor="Green" Font-Bold="true" />

</form>

</body></html>

Output-

Bhumika wadhwa 38
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-11

Aim- To write a program using conditional statements and loops to generate number patterns
such as triangle and diamond.

Procedure-

 Create a new [Link] Web Form.


 Add a TextBox to enter number of rows.
 Add a Button to generate patterns.
 Use loops (for loop) to generate triangle and diamond patterns.
 Display output using Literal control.
 Run the program.

Code-

[Link]

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"


Inherits="Practical11.Default11" %>

<html><body>

<form id="form1" runat="server">

<h2>Number Patterns</h2>

Rows: <asp:TextBox ID="txtRows" runat="server" Text="5" />

<asp:Button ID="btnGen" runat="server" Text="Generate" OnClick="btnGen_Click" />

<br /><br />

Triangle:

<pre><asp:Literal ID="litTriangle" runat="server" /></pre>

Diamond:

<pre><asp:Literal ID="litDiamond" runat="server" /></pre>

</form>

</body></html>

Bhumika wadhwa 39
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
[Link]

using System;

using [Link];

namespace Practical11

public partial class Default11 : [Link]

protected void btnGen_Click(object sender, EventArgs e)

int n = [Link]([Link]);

// Triangle

string t = "";

for (int i = 1; i <= n; i++)

for (int j = 1; j <= i; j++)

t += j + " ";

t += "\n";

[Link] = t;

// Diamond

string d = "";

// Upper

for (int i = 1; i <= n; i++)

Bhumika wadhwa 40
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
{

d += new string(' ', n - i);

for (int j = 1; j <= 2 * i - 1; j++)

d += (j % 2 == 0) ? " " : ((j + 1) / 2).ToString();

d += "\n";

// Lower

for (int i = n - 1; i >= 1; i--)

d += new string(' ', n - i);

for (int j = 1; j <= 2 * i - 1; j++)

d += (j % 2 == 0) ? " " : ((j + 1) / 2).ToString();

d += "\n";

[Link] = d;

Output-

Bhumika wadhwa 41
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS

Bhumika wadhwa 42
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-12

Aim- To write a program using conditional statements and loops to test whether a number is
prime or not.

Procedure-

1. Create a new [Link] Web Form.


2. Add a TextBox to enter a number.
3. Add a Button to check prime number.
4. Use loop and conditional statements to check divisibility.
5. Display result using Label control.
6. Run the application.

Code-

[Link]

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"


Inherits="Practical12.Default12" %>

<html><body>

<form id="form1" runat="server">

<h2>Prime Number Check</h2>

Enter Number: <asp:TextBox ID="txtNum" runat="server" />

<asp:Button ID="btnCheck" runat="server" Text="Check" OnClick="btnCheck_Click" />

<br /><br />

<asp:Label ID="lblResult" runat="server" Font-Bold="true" />

</form>

</body></html><%@ Page Language="C#" AutoEventWireup="true"


CodeBehind="[Link]" Inherits="Practical12.Default12" %>

<html><body>

<form id="form1" runat="server">

<h2>Prime Number Check</h2>

Bhumika wadhwa 43
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
Enter Number: <asp:TextBox ID="txtNum" runat="server" />

<asp:Button ID="btnCheck" runat="server" Text="Check" OnClick="btnCheck_Click" />

<br /><br />

<asp:Label ID="lblResult" runat="server" Font-Bold="true" />

</form>

</body></html>

[Link]

using System;

namespace Practical12

public partial class Default12 : [Link]

protected void btnCheck_Click(object sender, EventArgs e)

int num = [Link]([Link]);

bool isPrime = true;

if (num <= 1)

isPrime = false;

else

for (int i = 2; i <= num / 2; i++)

if (num % i == 0)

Bhumika wadhwa 44
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
{

isPrime = false;

break;

if (isPrime)

[Link] = num + " is a Prime Number";

else

[Link] = num + " is not a Prime Number";

Output-

Bhumika wadhwa 45
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-13

Aim- To create a program using ListBox, Button, Image, and Label controls to display the
selected item’s image.

Procedure-

 Create a new [Link] Web Form.


 Add a ListBox control and insert store items.
 Add an Image control to display item images.
 Add a Label control to show selected item name.
 Add a Button control.
 Write code to display image based on selected item.
 Run the application.

Code-

[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="[Link]" %>

<!DOCTYPE html>

<html>

<body>

<form runat="server">

<asp:ListBox ID="lstItems" runat="server" AutoPostBack="true"

OnSelectedIndexChanged="lstItems_SelectedIndexChanged">

<asp:ListItem Value="apple">Apple - $1.00</asp:ListItem>

<asp:ListItem Value="banana">Banana - $0.50</asp:ListItem>

<asp:ListItem Value="mango">Mango - $1.50</asp:ListItem>

<asp:ListItem Value="grape">Grape - $2.00</asp:ListItem>

</asp:ListBox>

Bhumika wadhwa 46
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
<br /><br />

<asp:Image ID="imgItem" runat="server" Width="150px" />

<br /><br />

<asp:Button ID="btnShowCost" runat="server" Text="Show Cost"

OnClick="btnShowCost_Click" />

<br /><br />

<asp:Label ID="lblCost" runat="server"></asp:Label>

</form>

</body>

</html>

[Link]

using System;

using [Link];

namespace Practical1

public partial class Default : [Link]

Dictionary<string, decimal> prices = new Dictionary<string, decimal>()

{"apple", 1.00m},

{"banana", 0.50m},

{"mango", 1.50m},

{"grape", 2.00m}

Bhumika wadhwa 47
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
};

Dictionary<string, string> images = new Dictionary<string, string>()

{"apple", "[Link]

{"banana", "[Link]

{"mango", "[Link]

{"grape", "[Link]

};

protected void lstItems_SelectedIndexChanged(object sender, EventArgs e)

string selected = [Link];

[Link] = images[selected];

protected void btnShowCost_Click(object sender, EventArgs e)

string selected = [Link];

[Link] = "Cost: $" + prices[selected];

Output-

Bhumika wadhwa 48
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS

Bhumika wadhwa 49
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-14

Aim- To create a program that accepts user details like username, mode of payment and credit
card, and validates the input using [Link] validation controls.

Procedure-

 Create a new [Link] Web Form.


 Add TextBox for username.
 Add RadioButtonList for mode of payment.
 Add TextBox for credit card number.
 Add validation controls (RequiredFieldValidator, RegularExpressionValidator).
 Add a Button to validate input.
 Display result using Label control.
 Run the application.

Code-

[Link]

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"


Inherits="Practical14.Default14" %>

<html><body>

<form id="form1" runat="server">

<h2>Payment Form</h2>

User Name:

<asp:TextBox ID="txtName" runat="server" />

<asp:RequiredFieldValidator runat="server" ControlToValidate="txtName"

ErrorMessage="Name required" ForeColor="Red" />

<br /><br />

Mode of Payment:

<asp:RadioButtonList ID="rblPayment" runat="server">

<asp:ListItem>Credit Card</asp:ListItem>

Bhumika wadhwa 50
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
<asp:ListItem>Debit Card</asp:ListItem>

<asp:ListItem>Net Banking</asp:ListItem>

</asp:RadioButtonList>

<asp:RequiredFieldValidator runat="server" ControlToValidate="rblPayment"

InitialValue="" ErrorMessage="Select payment mode" ForeColor="Red" />

<br /><br />

Credit Card No:

<asp:TextBox ID="txtCard" runat="server" />

<asp:RequiredFieldValidator runat="server" ControlToValidate="txtCard"

ErrorMessage="Card number required" ForeColor="Red" />

<asp:RegularExpressionValidator runat="server" ControlToValidate="txtCard"

ValidationExpression="^\d{16}$"

ErrorMessage="Enter 16 digit card number" ForeColor="Red" />

<br /><br />

<asp:Button ID="btnValidate" runat="server" Text="Validate" OnClick="btnValidate_Click" />

<br /><br />

<asp:Label ID="lblResult" runat="server" Font-Bold="true" ForeColor="Green" />

</form>

</body></html>

[Link]
using System;

namespace Practical14

public partial class Default14 : [Link]

Bhumika wadhwa 51
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
protected void btnValidate_Click(object sender, EventArgs e)

if ([Link])

[Link] = "Validation Successful! Welcome " + [Link];

Output-

Bhumika wadhwa 52
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
PRACTICAL-15

Aim- To write a program using conditional statements and loops to generate Fibonacci series .

Procedure-

1. Create a new [Link] Web Form.


2. Add a TextBox to enter number of terms.
3. Add a Button to generate Fibonacci series.
4. Use loop to generate series.
5. Display output using Label control.
6. Run the application.

Code-

[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]"
Inherits="Practical15.Default15" %>

<html>

<body>

<form id="form1" runat="server">

<h2>Fibonacci Series Generator</h2>

How many terms?

<asp:TextBox ID="txtTerms" runat="server" Width="60px" />

<asp:Button ID="btnGen" runat="server" Text="Generate" OnClick="btnGen_Click" />

<br /><br />

<asp:Label ID="lblResult" runat="server" Font-Bold="true" ForeColor="DarkBlue" />

<br /><br />

<asp:Literal ID="litTable" runat="server" />

</form>

</body>

Bhumika wadhwa 53
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
</html>

[Link]

using System;

using [Link];

using [Link];

namespace Practical15

public partial class Default15 : Page

protected void btnGen_Click(object sender, EventArgs e)

if (![Link]([Link], out int n) || n < 1)

[Link] = "Enter a valid number of terms.";

return;

long[] fib = new long[n];

fib[0] = 0;

if (n > 1) fib[1] = 1;

for (int i = 2; i < n; i++)

fib[i] = fib[i - 1] + fib[i - 2];

// Display as series

[Link] = "Fibonacci Series: " + [Link](", ", fib);

Bhumika wadhwa 54
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
// Display as HTML table

var sb = new StringBuilder();

[Link]("<table border='1' cellpadding='8' style='border-collapse:collapse;'>");

[Link]("<tr
style='background:#003366;color:white'><th>Term</th><th>Value</th></tr>");

for (int i = 0; i < n; i++)

[Link]($"<tr><td>{i + 1}</td><td>{fib[i]}</td></tr>");

[Link]("</table>");

[Link] = [Link]();

Output-

Bhumika wadhwa 55

You might also like