A Basic calculator Web Appliation in c#

SOURCE FILE :
 
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="4-3.aspx.cs" Inherits="lab_4._4_3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Simple Calculator</title>
<style type="text/css">
.auto-style1 {
width: 50%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>

<table align="center" cellpadding="0" cellspacing="0" class="auto-style1">
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">Calculator</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">
<asp:TextBox ID="txtDisplay" runat="server" Width="243px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">
<asp:Label ID="l1" runat="server" ForeColor="Red"></asp:Label>
</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">
<asp:Button ID="btOne" runat="server" OnClick="btOne_Click" Text="1" Width="40px" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btTwo" runat="server" Text="2" Width="40px" OnClick="btTwo_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btThree" runat="server" Text="3" Width="40px" OnClick="btThree_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btAdd" runat="server" Text="+" Width="40px" OnClick="btAdd_Click" />
</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;&nbsp;&nbsp;
<asp:Button ID="btFour" runat="server" Text="4" Width="40px" OnClick="btFour_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btFive" runat="server" Text="5" Width="40px" OnClick="btFive_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btSix" runat="server" Text="6" Width="40px" OnClick="btSix_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btSub" runat="server" Text="-" Width="40px" OnClick="btSub_Click" />
&nbsp;&nbsp;&nbsp; </td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;<asp:Button ID="btSeven" runat="server" Text="7" Width="40px" OnClick="btSeven_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btEight" runat="server" Text="8" Width="40px" OnClick="btEight_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btNine" runat="server" Text="9" Width="40px" OnClick="btNine_Click" />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="btMul" runat="server" Text="*" Width="40px" OnClick="btMul_Click" />
</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;
<asp:Button ID="btClear" runat="server" Text="C" Width="40px" OnClick="btClear_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btZero" runat="server" Text="0" Width="40px" OnClick="btZero_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btResult" runat="server" Text="=" Width="40px" OnClick="btResult_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btDiv" runat="server" Text="/" Width="40px" OnClick="btDiv_Click" />
</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
<tr>
<td style="text-align:center">&nbsp;</td>
</tr>
</table>

</div>
</form>
</body>
</html>
 
 
 
CS file :
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lab_4
{
public partial class _4_3 : System.Web.UI.Page
{
static double value1, value2, result;
static char op;

protected void Page_Load(object sender, EventArgs e)
{
txtDisplay.Focus();
}

protected void btOne_Click(object sender, EventArgs e)
{
if ((txtDisplay.Text == "+") || (txtDisplay.Text == "-") || (txtDisplay.Text == "*") || (txtDisplay.Text == "/"))
{
txtDisplay.Text = "";
txtDisplay.Text = txtDisplay.Text + btOne.Text;
}
else
{
txtDisplay.Text = txtDisplay.Text + btOne.Text;
}
}

protected void btTwo_Click(object sender, EventArgs e)
{
if ((txtDisplay.Text == "+") || (txtDisplay.Text == "-") || (txtDisplay.Text == "*") || (txtDisplay.Text == "/"))
{
txtDisplay.Text = "";
txtDisplay.Text = txtDisplay.Text + btTwo.Text;
}
else
{
txtDisplay.Text = txtDisplay.Text + btTwo.Text;
}
}

protected void btThree_Click(object sender, EventArgs e)
{
if ((txtDisplay.Text == "+") || (txtDisplay.Text == "-") || (txtDisplay.Text == "*") || (txtDisplay.Text == "/"))
{
txtDisplay.Text = "";
txtDisplay.Text = txtDisplay.Text + btThree.Text;
}
else
{
txtDisplay.Text = txtDisplay.Text + btThree.Text;
}
}

protected void btFour_Click(object sender, EventArgs e)
{
if ((txtDisplay.Text == "+") || (txtDisplay.Text == "-") || (txtDisplay.Text == "*") || (txtDisplay.Text == "/"))
{
txtDisplay.Text = "";
txtDisplay.Text = txtDisplay.Text + btFour.Text;
}
else
{
txtDisplay.Text = txtDisplay.Text + btFour.Text;
}
}

protected void btFive_Click(object sender, EventArgs e)
{
if ((txtDisplay.Text == "+") || (txtDisplay.Text == "-") || (txtDisplay.Text == "*") || (txtDisplay.Text == "/"))
{
txtDisplay.Text = "";
txtDisplay.Text = txtDisplay.Text + btFive.Text;
}
else
{
txtDisplay.Text = txtDisplay.Text + btFive.Text;
}
}

protected void btSix_Click(object sender, EventArgs e)
{
if ((txtDisplay.Text == "+") || (txtDisplay.Text == "-") || (txtDisplay.Text == "*") || (txtDisplay.Text == "/"))
{
txtDisplay.Text = "";
txtDisplay.Text = txtDisplay.Text + btSix.Text;
}
else
{
txtDisplay.Text = txtDisplay.Text + btSix.Text;
}
}

protected void btSeven_Click(object sender, EventArgs e)
{
if ((txtDisplay.Text == "+") || (txtDisplay.Text == "-") || (txtDisplay.Text == "*") || (txtDisplay.Text == "/"))
{
txtDisplay.Text = "";
txtDisplay.Text = txtDisplay.Text + btSeven.Text;
}
else
{
txtDisplay.Text = txtDisplay.Text + btSeven.Text;
}
}

protected void btEight_Click(object sender, EventArgs e)
{
if ((txtDisplay.Text == "+") || (txtDisplay.Text == "-") || (txtDisplay.Text == "*") || (txtDisplay.Text == "/"))
{
txtDisplay.Text = "";
txtDisplay.Text = txtDisplay.Text + btEight.Text;
}
else
{
txtDisplay.Text = txtDisplay.Text + btEight.Text;
}
}

protected void btNine_Click(object sender, EventArgs e)
{
if ((txtDisplay.Text == "+") || (txtDisplay.Text == "-") || (txtDisplay.Text == "*") || (txtDisplay.Text == "/"))
{
txtDisplay.Text = "";
txtDisplay.Text = txtDisplay.Text + btNine.Text;
}
else
{
txtDisplay.Text = txtDisplay.Text + btNine.Text;
}
}

protected void btZero_Click(object sender, EventArgs e)
{
if ((txtDisplay.Text == "+") || (txtDisplay.Text == "-") || (txtDisplay.Text == "*") || (txtDisplay.Text == "/"))
{
txtDisplay.Text = "";
txtDisplay.Text = txtDisplay.Text + btZero.Text;
}
else
{
txtDisplay.Text = txtDisplay.Text + btZero.Text;
}
}

protected void btClear_Click(object sender, EventArgs e)
{
txtDisplay.Text = "";
l1.Text = "";
}

protected void btAdd_Click(object sender, EventArgs e)
{
value1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "";
op = '+';
txtDisplay.Text = txtDisplay.Text + op;

}

protected void btSub_Click(object sender, EventArgs e)
{
value1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "";
op = '-';
txtDisplay.Text = txtDisplay.Text + op;
}

protected void btMul_Click(object sender, EventArgs e)
{
value1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "";
op = '*';
txtDisplay.Text = txtDisplay.Text + op;
}

protected void btDiv_Click(object sender, EventArgs e)
{
value1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "";
op = '/';
txtDisplay.Text = txtDisplay.Text + op;
}

protected void btResult_Click(object sender, EventArgs e)
{
value2 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "";
l1.Text = "";
if (op == '+')
{
result = value1 + value2;
txtDisplay.Text = txtDisplay.Text + result;
}
else if (op == '-')
{
result = value1 - value2;
txtDisplay.Text = txtDisplay.Text + result;
}

else if (op == '*')
{
result = value1 * value2;
txtDisplay.Text = txtDisplay.Text + result;
}
else
{
if (value2 == 0)
{
l1.Text = "divide by zero";
}
else
{
result = value1 * value2;
txtDisplay.Text = txtDisplay.Text + result;
}
}

}

}