0% found this document useful (0 votes)
17 views26 pages

Practical No:01

Uploaded by

Sayyed Aadil
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)
17 views26 pages

Practical No:01

Uploaded by

Sayyed Aadil
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/ 26

T.Y.BSc(I.

T) SEM-V Advanced Web Programming

Practical No:01
Working with basic C# and ASP .NET
a)Create an application that obtains four int values from the user and displays the
product.

Code:
Product.aspx
<%@PageLanguage="C#"AutoEventWireup="true"
CodeBehind="Product.aspx.cs"Inherits="Practical1_a_.Product" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<center>
<asp:Image ID="Image1" runat="server" Height="199px" ImageUrl="~/WhatsApp
Image 2024-07-26 at 16.56.43_b52d341c.jpg" Width="228px" />
<br />
<asp:Label ID="lbl6" runat="server" Font-Bold="True" Font-Italic="True" Font-
Size="XX-Large" Font-Underline="True" Text="Mohammad Arbaz 48"></asp:Label>
<br />
<br />
<asp:Label ID="lbl1" runat="server" BorderStyle="Ridge" Text="Enter First
Number:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt1" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />
<asp:Label ID="lbl2" runat="server" BorderStyle="Ridge" Text="Enter Second
Number:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt2" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />
<asp:Label ID="lbl3" runat="server" BorderStyle="Ridge" Text="Enter Third
Number:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt3" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />
<asp:Label ID="lbl4" runat="server" BorderStyle="Ridge" Text="Enter Fourth
Number:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt4" runat="server" BorderStyle="Ridge"></asp:TextBox>

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

<br />
<br />
<asp:Button ID="btn1" runat="server" BorderStyle="Ridge" OnClick="btn1_Click"
Text="Calculate" />
<br />
<br />

<asp:LabelID="lbl5"runat="server"Text="Output"BorderStyle="Ridge"></asp:Label>
<br />
</center>
</form>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
</body>
</html>

Design:

Product.aspx.cs

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

namespace Practical1_a_
{
public partial class Product : System.Web.UI.Page

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

{
protected void Page_Load(object sender, EventArgs e)
{

protected void btn1_Click(object sender, EventArgs e)


{
int num1 = Convert.ToInt32(txt1.Text);
int num2 = Convert.ToInt32(txt2.Text);
int num3 = Convert.ToInt32(txt3.Text);
int num4 = Convert.ToInt32(txt4.Text);

int product = num1 * num2 * num3 * num4;


lbl5.Text = "Product of numbers: " + product;
txt1.Text = "";
txt2.Text = "";
txt3.Text = "";
txt4.Text = "";
txt1.Focus();
}
}
}

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

Output:

b) Create an application to demonstrate string operations.

Name.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Name.aspx.cs"
Inherits="Practical1_b_.Name" %>

<!DOCTYPE html>

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

<asp:Image ID="Image1" runat="server" Height="219px" ImageUrl="~/WhatsApp


Image 2024-07-26 at 16.56.43_22aa4b10.jpg" Width="223px" />
<br />
<asp:Label ID="lbl4" runat="server" Font-Bold="True" Font-Italic="True" Font-
Size="XX-Large" Font-Underline="True" Text="Mohammad Arbaz 48"></asp:Label>
<br />
<br />
<asp:Label ID="lbl1" runat="server" BorderStyle="Ridge" Text="Enter First
String"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt1" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

<asp:Label ID="lbl2" runat="server" BorderStyle="Ridge" Text="Enter First


String"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt2" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Concate</asp:ListItem>
<asp:ListItem>UpperCase</asp:ListItem>
<asp:ListItem>LowerCase</asp:ListItem>
<asp:ListItem>Reverse</asp:ListItem>
<asp:ListItem>Length</asp:ListItem>
<asp:ListItem>IsEmpty</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Button ID="btn1" runat="server" BorderStyle="Ridge"
OnClick="btn1_Click" Text="Submit" />
<br />
<br />
<asp:Label ID="lbl3" runat="server" Text="Result"
BorderStyle="Ridge"></asp:Label>

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

Design:

Name.aspx.cs

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V 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 Practical1_b_
{
public partial class Name : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

protected void btn1_Click(object sender, EventArgs e)


{
String str1 = txt1.Text.ToString();
String str2 = txt2.Text.ToString();
if (DropDownList1.SelectedItem.Text.Equals("Concate"))
{
lbl3.Text = "Concatinate String: " +(str1+str2);
}
else if (DropDownList1.SelectedItem.Text.Equals("UpperCase"))
{
lbl3.Text = "<br>" + "Upper case of String :" + "<br>" + (str1.ToUpper() + " "
+str2.ToUpper());
}
else if (DropDownList1.SelectedItem.Text.Equals("LowerCase"))
{
lbl3.Text = "<br>" + "Lower case of String :" + "<br>" + str1.ToLower() + " "
+str2.ToLower();
}
else if (DropDownList1.SelectedItem.Text.Equals("Length"))
{
lbl3.Text = "<br>" + "Length of first string " + str1 + ":<br>" + str1.Length;
}
else if (DropDownList1.SelectedItem.Text.Equals("IsEmpty"))
{
if(String.IsNullOrEmpty(str1) && String.IsNullOrEmpty(str2))
{
lbl3.Text = "<br>" + "Both the textbox is empty";
}
else if (String.IsNullOrEmpty(str1))
{

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

lbl3.Text = "TextBox 1 is Empty";


}
else if(String.IsNullOrEmpty(str2))
{
lbl3.Text = "TextBox 2 is Empty";
}
else
{
lbl3.Text = "None of the TextBox is Empty";
}
}
else
{
String reverse1=new string(str1.Reverse().ToArray());
String reverse2=new string(str2.Reverse().ToArray());
lbl3.Text = "Reverse of 1st string :" + reverse1;
}
}
}
}

Output:

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

c) Create an application to demonstrate following operations


i. Generate Fibonacci series. ii. Test for prime numbers.
iii. Test for vowels. iv. Use of foreach loop with arrays
v. Reverse a number and find sum of digits of a number.

Fibonacci.aspx

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


Inherits="Practical1_c_.Fibonacci" %>

<!DOCTYPE html>

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

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

</head>
<body>
<form id="form1" runat="server">
<center>

<asp:Image ID="Image1" runat="server" Height="215px" ImageUrl="~/WhatsApp


Image 2024-07-26 at 16.56.43_f9886562.jpg" Width="215px" />
<br />
<asp:Label ID="lbl4" runat="server" Font-Bold="True" Font-Italic="True" Font-
Size="XX-Large" Font-Underline="True" Text="Mohammad Arbaz 48"></asp:Label>
<br />
<br />
<asp:Label ID="lbl1" runat="server" BorderStyle="Ridge" Text="Enter First
String"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt1" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />
<asp:Label ID="lbl2" runat="server" Text="Select your Operation:"></asp:Label>
&nbsp;&nbsp;
<br />
&nbsp;<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Fibonacci</asp:ListItem>
<asp:ListItem>Prime</asp:ListItem>
<asp:ListItem>Vowels</asp:ListItem>
<asp:ListItem>foreach loop</asp:ListItem>
<asp:ListItem>Reverse and Find sum of Digit</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Button ID="btn1" runat="server" BorderStyle="Ridge"
OnClick="btn1_Click" Text="Submit" />
<br />
<br />
<asp:Label ID="lbl3" runat="server" BorderStyle="Ridge"
Text="Result"></asp:Label>

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

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

Design:

Fibonacci.aspx.cs

using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

protected void btn1_Click(object sender, EventArgs e)


{
if (DropDownList1.SelectedItem.Text.Equals("Fibonacci"))
{
int usrInputNumber=Convert.ToInt32(txt1.Text.ToString());
int fno = 0;
int sno = 1;

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

int sum = 0;
Response.Write("fibonacci Series: " + fno + "," + sno);
int i = 2;
while (i < usrInputNumber)
{
sum = fno + sno;
Response.Write("," + sum);
fno = sno;
sno = sum;
i++;
}
}
else if (DropDownList1.SelectedItem.Text.Equals("Prime"))
{
int num1 = Convert.ToInt32(txt1.Text.ToString());
int i;
for(i=2;i<num1-1;i++)
{
if (num1 % i == 0)
{
break;
}
if (i < num1 - 1)
{
lbl3.Text = "IS NOT A PRIME NUMBER";
}
else
{
lbl3.Text = "A PRIME NUMBER";
}
}
}
else if (DropDownList1.SelectedItem.Text.Equals("Vowels"))
{
string str=txt1.Text.ToString().ToLower();
int c = 0;
for(int i=0;i<str.Length;i++)
{
if ((str.Substring(i, 1)) == "a" || (str.Substring(i, 1)) == "e" || (str.Substring(i,
1)) == "i" || (str.Substring(i, 1)) == "o" || (str.Substring(i, 1)) == "u")
{
c++;
}
}
lbl3.Text = ("Total number of vowels in " + str + " is " + c);
}
else if(DropDownList1.SelectedItem.Text.Equals("Reverse and Find sum of
Digit"))
{
int num1=Convert.ToInt32(txt1.Text.ToString());

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

int reverse = 0;
int sum = 0;
while(num1 != 0)
{
int remainder = num1 % 10;
reverse=reverse*10 + remainder;
sum=remainder+sum;
num1=num1/10;
}
lbl3.Text = "<br>" + "Reverse of entered number is" + reverse + "<br>" + "Sum
of digits is" + sum;
}
else
{
String s = txt1.Text.ToString();
foreach(char c in s)
{
Response.Write("<br>" + c);
}
}
}
}
}

Output:

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

Practical No:02
Working with Object Oriented C# and ASP .NET
a)Create simple application to perform following operations
i. Finding factorial Value ii. Money Conversion
iii. Quadratic Equation iv. Temperature Conversion

i. Finding Factorial Value


Factorial.aspx

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


Inherits="Practical2_a_i.Factorial" %>

<!DOCTYPE html>

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

<asp:Image ID="Image1" runat="server" Height="221px" ImageUrl="~/WhatsApp


Image 2024-07-26 at 16.56.43_891d895d.jpg" Width="204px" />
<br />
<asp:Label ID="lbl3" runat="server" Font-Bold="True" Font-Italic="True" Font-
Size="XX-Large" Font-Underline="True" Text="Mohammad Arbaz 48"></asp:Label>
<br />
<br />
<asp:Label ID="lbl1" runat="server" BorderStyle="Ridge" Text="Enter a
Number:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt1" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />
<asp:Button ID="btn1" runat="server" BorderStyle="Ridge"
OnClick="Button1_Click" Text="Factorial" />
<br />
<br />
<asp:Label ID="lbl2" runat="server" BorderStyle="Ridge"
Text="Output"></asp:Label>

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

Design:

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

Factorial.aspx.cs

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

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

protected void Button1_Click(object sender, EventArgs e)


{
int num = Convert.ToInt32(txt1.Text);
int fact = 1;
for(int i=1; i<=num; i++)
{
fact =fact * i;
lbl2.Text = "Factorial is = " + fact;
txt1.Text = "";
txt1.Focus();
}
}
}
}

Output:

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

ii. Money Conversion

MoneyConversion.aspx

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


CodeBehind="MoneyConversion.aspx.cs" Inherits="Practical2_a_ii.MoneyConversion"
%>

<!DOCTYPE html>

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

<asp:Image ID="Image1" runat="server" Height="249px" ImageUrl="~/WhatsApp


Image 2024-07-26 at 16.56.43_0dcea784.jpg" Width="253px" />
<br />
<asp:Label ID="lbl4" runat="server" Font-Bold="True" Font-Italic="True" Font-
Size="XX-Large" Font-Underline="True" Text="Mohammad Arbaz 48"></asp:Label>
<br />
<br />
<asp:Label ID="lbl1" runat="server" BorderStyle="Ridge" Text="Enter The
Amount:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt1" runat="server" BorderStyle="Ridge"></asp:TextBox>

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

<br />
<br />
<asp:Label ID="lbl2" runat="server" BorderStyle="Ridge" Text="Select The
Conversion"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Rupees to Dollar</asp:ListItem>
<asp:ListItem>Dollar to Rupees</asp:ListItem>
<asp:ListItem>Rupees to Euro</asp:ListItem>
<asp:ListItem>Euro to Rupees</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Button ID="btn1" runat="server" BorderStyle="Ridge" OnClick="btn1_Click"
Text="Convert" />
<br />
<br />
<asp:Label ID="lbl3" runat="server" BorderStyle="Ridge"
Text="Output"></asp:Label>

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

Design:

MoneyConversion.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

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

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

protected void btn1_Click(object sender, EventArgs e)


{
double amt = Convert.ToDouble(txt1.Text);
String Conversion = DropDownList1.SelectedValue;
double ans = 0;
if(Conversion.Equals("Rupees to Dollar"))
{
ans = amt / 83;
}
else if(Conversion.Equals("Dollar to Rupees"))
{
ans = amt * 83;
}
else if(Conversion.Equals("Rupees to Euro"))
{
ans = amt / 102;
}
else if(Conversion.Equals("Euro to Rupees"))
{
ans = amt * 102;
}
lbl3.Text = "Ans = " + ans;
}
}
}

Output:

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

iii. Quadratic Equation

QuadraticEquation.aspx

<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="QuadraticEquation.aspx
.cs" Inherits="Practical2_a_iii.QuadraticEquation" %>

<!DOCTYPE html>

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

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<center>

<asp:Image ID="Image1" runat="server" Height="259px" ImageUrl="~/WhatsApp


Image 2024-07-26 at 16.56.43_519bafa8.jpg" Width="248px" />
<br />
<asp:Label ID="lbl4" runat="server" BorderStyle="None" Font-Bold="True" Font-
Italic="True" Font-Size="XX-Large" Font-Underline="True" Text="Mohammad Arbaz
48"></asp:Label>
<br />
<br />
<asp:Label ID="lbl1" runat="server" BorderStyle="Ridge" Text="Enter value of
a:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt1" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />
<asp:Label ID="lbl2" runat="server" BorderStyle="Ridge" Text="Enter value of
b:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt2" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />
<asp:Label ID="lbl3" runat="server" BorderStyle="Ridge" Text="Enter value of
c:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt3" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />
<asp:Button ID="btn1" runat="server" BorderStyle="Ridge" OnClick="btn1_Click"
Text="Result" />

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

Design:

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

QuadraticEquation.aspx.cs

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

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

}
public class quadeqtn
{
public double d, x1, x2;
public string msg;
public quadeqtn(int a,int b,int c)
{
d = b * b - 4 * a * c;
if (d == 0)
{
x1 = -b / (2.0 * a);
x2 = x1;
msg = "Boths the roots are equal<br>1st Root is: " + x1 + "<br>2nd Root is: "
+ x2 + "<br>";
}
else if (d > 0)
{

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

x1 = (-b + Math.Sqrt(d)) / (2 * a);


x2 = (-b - Math.Sqrt(d)) / (2 * a);
msg = "Both the roots are real and different<br>1st Root is: " + x1 + "<br>2nd
Root is: " + x2 + "<br>";
}
else
{
msg = "Roots are imaginary,No solution,";
}
}
}
protected void btn1_Click(object sender, EventArgs e)
{
int a, b, c;
a = Int32.Parse(txt1.Text);
b = Int32.Parse(txt2.Text);
c = Int32.Parse(txt3.Text);

quadeqtn qe = new quadeqtn(a, b, c);


Response.Write(qe.msg);
}
}
}

Output:

iv. Temperature Conversion

TemperatureConversion.aspx

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

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


CodeBehind="TemperatureConversion.aspx.cs"
Inherits="Practical2_a_iv.TemperatureConversion" %>

<!DOCTYPE html>

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

<asp:Image ID="Image1" runat="server" Height="243px" ImageUrl="~/WhatsApp


Image 2024-07-26 at 16.56.43_e59ae64b.jpg" Width="241px" />
<br />
<asp:Label ID="lbl5" runat="server" Font-Bold="True" Font-Italic="True" Font-
Size="XX-Large" Font-Underline="True" Text="Mohammad Arbaz 48"></asp:Label>
<br />
<br />
<asp:Label ID="lbl1" runat="server" BorderStyle="Ridge"
Text="Celcius:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt1" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />
<asp:Button ID="btn1" runat="server" BorderStyle="Ridge"
OnClick="btn1_Click" Text="Celcius to Fahrenheit" />
<br />
<br />
<asp:Label ID="lbl2" runat="server" BorderStyle="Ridge"
Text="Fahrenheit:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt2" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />
<asp:Label ID="lbl3" runat="server" BorderStyle="Ridge"
Text="Fahrenheit:"></asp:Label>
&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txt3" runat="server" BorderStyle="Ridge"></asp:TextBox>
<br />
<br />
<asp:Button ID="btn2" runat="server" BorderStyle="Ridge"
OnClick="btn2_Click" Text="Fahrenheit to Celcius" />
<br />
<br />
<asp:Label ID="lbl4" runat="server" BorderStyle="Ridge"
Text="Celcius:"></asp:Label>
&nbsp;&nbsp;&nbsp;

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

<asp:TextBox ID="txt4" runat="server" BorderStyle="Ridge"></asp:TextBox>


<br />

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

Design:

TemperatureConversion.aspx.cs

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

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

}
public class convert
{
public double temp, f, c;
public convert(double t)
{

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

temp = t;
}
public void ctf()
{
f = ((temp * 9 / 5)) + 32;
}
public void ftc()
{
c = ((temp - 32) * 5) / 9;
}
}

protected void btn1_Click(object sender, EventArgs e)


{
double c= Double.Parse(txt1.Text);
convert obj = new convert(c);
obj.ctf();
txt2.Text=obj.f.ToString();
}

protected void btn2_Click(object sender, EventArgs e)


{
double c = Double.Parse(txt3.Text);
convert obj = new convert(c);
obj.ftc();
txt4.Text=obj.c.ToString();
}
}
}

Output:

Mohammad Arbaz 48
T.Y.BSc(I.T) SEM-V Advanced Web Programming

Mohammad Arbaz 48

You might also like