ASP Practical File

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 25

SESSION – 2019-22

BRANCH- CS&IT
SEMESTER- Vth

PRACTICAL RECORD OF ASP.NET

SUBMITTED BY: AMIT KUMAR VERMA SUBMITTED TO: MR UDAY RANJAN


ROLL NO. – R19CA1CA0004
COURSE CODE – 3IBCA 501

EXTERNAL SIGNATURE: INTERNAL SIGNATURE:

ACKNOWLEDGEMENT –
I would like to thank my teacher Mr Uday Ranjan Sir who gave me this
opportunity to work on this assignment (Lab Manual). I got to learn a lot from
this assignment about: -
1. Design web applications using ASP.NET.
2. ASP.NET controls in web applications.
3. Debug and deploy ASP.NET web applications
4. Create database driven ASP.NET web applications and web service
I would like to thank my dear friends who have been with me all the time.

INDEX
S_No Topic Page_No Remarks
01 Write a program using 4 to 5
RequiredFieldValidation in ASP.NET.

02 Write a program using Regular Expression 6 to 7


Validation in ASP.NET.

2
03 Write a program using Compare Validation 8 to 9
in ASP.NET to check the password entered
by the user is correct or not, if the
password is correct then page will be
submitted.

04 WAP to validate the age entered by the 10 to 11


user is between 1 to 120 by using range
validation.

05 Write a program to check the number is odd, 12 to 14


i.e. display the message (Number must be odd)
by using custom validation.

06 Write programs using conditional statements 15


and loops: Generate Fibonacci series.

07 Write programs using conditional statements


and loops: Test for prime numbers.
16 to 17

08 Write programs using conditional 18 to 19


statements and loops: Reverse a number
and find sum of digits of a number.

09 Write a program using function 20 to 21


overloading to swap two integer numbers
and swap two float numbers.

10 Define a class „salary‟ which will contain 22 to 24


member variable Basic, TA, DA, HRA.
Write a program using Constructor with
default values for DA and HRA and
calculate the salary of employee.

PRACTICAL NO.: 01
AIM :- Write a program using RequiredFieldValidation in ASP.NET.

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

namespace RequiredFieldValidation

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

protected void btnSubmit_Click(object sender, EventArgs e)


{
lblDisplay.Text = "page is submitted";
}
}
}

When we click submit button without entering the input Username is Required message will
be display.

4
When we take the input and submit it then page is submitted message will be display.

5
PRACTICAL NO.: 02
AIM :- Write a program using Regular Expression Validation in ASP.NET.

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

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

protected void Button1_Click(object sender, EventArgs e)


{
lblDisplay.Text = "Page is submitted";
}
}
}

 When we take wrong input/format then this type of validation will be occurred.

6
And if we take write input/format then page will be successfully submitted.

7
PRACTICAL NO.: 03
AIM: - Write a program using Compare Validation in ASP.NET to check the
password entered by the user is correct or not, if the password is correct then
page will be submitted.

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

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

protected void Button1_Click(object sender, EventArgs e)


{
lblDisplay.Text = "page is submitted";
}
}
}

 When the user take wrong password

8
 When the user take correct password

9
PRACTICAL NO. : 04
AIM :- Write a program using to validate the age entered by the user is between 1 to
120 by using range validation :-

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

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

protected void Button1_Click(object sender, EventArgs e)


{
lblDisplay.Text="Page is submitted Successfully";
}
}
}

 When use take wrong input

10
 When user take right input :-

11
PRACTICAL NO. : 05
AIM :- Write a program to check the number is odd, i.e. display the message (Number must be odd)
by using custom validation :-

// Design Code
// JavaScript fn:-

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


Inherits="evenCustom.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" lang="ja"> // JavaScript function
function IsOdd(source, args) {
if (args.Value == "") {
args.IsValid = false;
}
else {
if (args.Value % 2 == 0) {
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
}

12
</script>
</head>
<body style="height: 235px; width: 1963px">
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Font-Bold="True" style="z-index: 1;
left: 11px; top: 9px; position: absolute" Text="Enter Number :"></asp:Label>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="txtNumber" Font-Bold="True" ForeColor="#CC0000" style="z-index: 1;
left: 384px; top: 25px; position: absolute" ClientValidationFunction="IsOdd">Number
must be odd</asp:CustomValidator>
<p>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" Font-Bold="True" style="z-index:
1; left: 51px; top: 86px; position: absolute; width: 74px" Text="Submit"
OnClick="Button1_Click" />
&nbsp;<asp:TextBox ID="txtNumber" runat="server" style="z-index: 1; left:
201px; top: 12px; position: absolute; height: 35px; width: 143px"></asp:TextBox>
</p>
<p>
&nbsp;</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="lblDisplay" runat="server" Font-Bold="True" style="z-index:
1; left: 154px; top: 103px; position: absolute" ForeColor="#CC0000"></asp:Label>
</p>
</form>
</body>
</html>

// Exectution code

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

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

protected void Button1_Click(object sender, EventArgs e)


{
lblDisplay.Text = "page is submitted successfully";
}
}
}

13
 When user take even number :-

 when user take correct input i.e odd number :

14
PRACTICAL NO. : 06
AIM: Write programs using conditional statements and loops: Generate Fibonacci series.

CODE:
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int num1=0,num2=1,num3,num4,num,counter;
Console.Write ("Upto how many number you want fibonacci series:");
num=int.Parse(Console.ReadLine());
counter=3; Console.Write(num1+"\t"+num2);
while(counter<=num) { num3 = num1 + num2;
if (counter >= num) break; Console.Write("\t" + num3);
num1 = num2; num2 = num3;
counter++;
}
}

15
}
}

OUTPUT:

PRACTICAL NO. : 07

AIM: Write programs using conditional statements and loops: III) Test for prime numbers.

CODE:

using System;

namespace testprime

class Program

static void Main(string[] args)

int num, counter;

16
Console.Write("Enter number:");

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

for (counter = 2; counter <= num / 2; counter++)

if ((num % counter) == 0)

break;

if (num == 1)

Console.WriteLine(num + "is neither prime nor composite");

else if(counter<(num/2))

Console.WriteLine(num+"is not prime number");

else

Console.WriteLine(num+"is prime number");

OUTPUT:

17
PRACTICAL NO. : 08

AIM: Write programs using conditional statements and loops:

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

18
CODE:

using System;

namespace reverseNumber

class Program

static void Main(string[] args)

int num,actualnumber,revnum=0,digit,sumDigits=0;

Console.Write("Enter number:"); num =

int.Parse(Console.ReadLine());

actualnumber = num;

while (num > 0)

digit = num % 10;

revnum = revnum * 10 + digit;

sumDigits=sumDigits+digit;

num = num / 10;

Console.WriteLine("Reverse of " + actualnumber + "=" +

revnum); Console.WriteLine("Sum of its digits:" + sumDigits);

19
OUTPUT:

PRACTICAL NO. : 09

20
AIM: Write a program using function overloading to swap two integer numbers and swap
two float numbers.

CODE:

using System;

namespace swap

class Overloading

public void swap(ref int n, ref int m)

int t;

t = n;

n = m;

m = t;

public void swap(ref float f1, ref float f2)

float f;

f = f1;

f1 = f2;

f2 = f;

class program

21
static void Main(string[] args)

Overloading objOverloading = new Overloading();

int n = 10, m = 20;

objOverloading.swap(ref n, ref m);

Console.WriteLine("N=" + n + "\tM=" + m);

float f1 = 10.5f, f2 = 20.6f;

objOverloading.swap(ref f1, ref f2);

Console.WriteLine("F1=" + f1 + "\tF2=" + f2);

OUTPUT :-

PRACTICAL NO. : 10

AIM: Define a class „salary‟ which will contain member variable Basic, TA, DA, HRA.
Write a program using Constructor with default values for DA and HRA and calculate the
salary of employee.

22
CODE:

Salary.cs

using System;

namespace SalaryConstructure

class Salary

int basic, ta, da, hra;

public Salary()

da = 9000;

hra = 6000;

public void getdata()

Console.Write("Enter basic salary : "); basic =

int.Parse(Console.ReadLine());

Console.Write("Enter travelling allowance : ");

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

public void showdata()

Console.WriteLine("Basic salary : " + basic);

Console.WriteLine("Dearness allowence : " + da);

Console.WriteLine("Housing rent allowence : " + hra);

23
Console.WriteLine("Travelling allowence : " + ta);

Console.WriteLine("Gross Salary : " + (basic + da + hra + ta));

Program.cs

using System;

namespace SalaryConstructure

class Program

static void Main(string[] args)

Salary s = new Salary();

s.getdata();

s.showdata();

OUTPUT:

Enter basic salary : 52000

Enter travelling allowance : 3000

24
Basic salary : 52000

Dearness allowence : 9000

Housing rent allowence : 6000

Travelling allowence : 3000

Gross Salary : 70000

25

You might also like