<%@ Page Language="C#" Debug="True" %>
<script runat="server">
void Page_Load()
{
btnAdd.BackColor = System.Drawing.Color.LightGray;
btnSubtract.BackColor = System.Drawing.Color.LightGray;
btnMultiply.BackColor = System.Drawing.Color.LightGray;
btnDivide.BackColor = System.Drawing.Color.LightGray;
}
void Add(object sender, EventArgs e)
{
double answer = Convert.ToDouble(txtInput1.Text) +
Convert.ToDouble(txtInput2.Text);
lblAnswer.Text = answer.ToString();
btnAdd.BackColor = System.Drawing.Color.Yellow;
}
void Subtract(object sender, EventArgs e)
{
double answer = Convert.ToDouble(txtInput1.Text) -
Convert.ToDouble(txtInput2.Text);
lblAnswer.Text = answer.ToString();
btnSubtract.BackColor = System.Drawing.Color.Yellow;
}
void Multiply(object sender, EventArgs e)
{
double answer = Convert.ToDouble(txtInput1.Text) *
Convert.ToDouble(txtInput2.Text);
lblAnswer.Text = answer.ToString();
btnMultiply.BackColor = System.Drawing.Color.Yellow;
}
void Divide(object sender, EventArgs e)
{
double answer = Convert.ToDouble(txtInput1.Text) /
Convert.ToDouble(txtInput2.Text);
lblAnswer.Text = answer.ToString();
btnDivide.BackColor = System.Drawing.Color.Yellow;
}
</script>
<html>
<head>
<title>Calculator example v1</title>
</head>
<body>
<form runat="server">
<h2>Calculator Version 1
</h2>
<asp:TextBox id="txtInput1" runat="server"></asp:TextBox>
<asp:Button id="btnAdd" onclick="Add" runat="server" Text=" + "></asp:Button>
<asp:Button id="btnSubtract" onclick="Subtract" runat="server" Text=" - "></asp:Button>
<br />
<asp:TextBox id="txtInput2" runat="server"></asp:TextBox>
<asp:Button id="btnMultiply" onclick="Multiply" runat="server" Text=" x "></asp:Button>
<asp:Button id="btnDivide" onclick="Divide" runat="server" Text="/"></asp:Button>
<br />
<strong>Answer = <asp:Label id="lblAnswer" runat="server"></asp:Label></strong>
</form>
</body>
</html>
|