Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="TemperatureConversion.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter the Value of Celsius : <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Celsius to Fahrenheit" />
<asp:Label ID="Label1" runat="server" Text=" F"></asp:Label>
</div> <p>
Enter the Value of Fahrenheit :<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Fahrenheit to Celsius " />
<asp:Label ID="Label2" runat="server" Text=" C"></asp:Label>
</p>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TemperatureConversion
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
TempConvert s = new TempConvert();
double n = Convert.ToDouble(TextBox1.Text);
double x = s.ctof(n);
Label1.Text = x.ToString()+"F";
}
protected void Button2_Click(object sender, EventArgs e)
{
TempConvert s = new TempConvert();
double n = Convert.ToDouble(TextBox2.Text);
double x = s.ftos(n);
Label2.Text = x.ToString()+"C";
}
}
public class TempConvert
{
public double ctof(double temp)
{
temp = (9.0 / 5.0 * temp )+ 32;
return temp;
}
public double ftos(double temp)
{
temp = (temp - 32)*5.0 / 9.0;
return temp;
}
}
}
0 Comments