<%@ Page Language="C#" Debug="True" %><script runat="server"> void Calc(object sender, EventArgs e) { double answer; Button PressedButton = (Button)sender; switch (PressedButton.ID) { case "btnAdd": answer = Convert.ToDouble(txtInput1.Text) + Convert.ToDouble(txtInput2.Text); lblAnswer.Text = answer.ToString(); break; case "btnSubtract": answer = Convert.ToDouble(txtInput1.Text) - Convert.ToDouble(txtInput2.Text); lblAnswer.Text = answer.ToString(); break; case "btnMultiply": answer = Convert.ToDouble(txtInput1.Text) * Convert.ToDouble(txtInput2.Text); lblAnswer.Text = answer.ToString(); break; case "btnDivide": answer = Convert.ToDouble(txtInput1.Text) / Convert.ToDouble(txtInput2.Text); lblAnswer.Text = answer.ToString(); break; } PressedButton.BackColor = System.Drawing.Color.Yellow; }
</script><html><head> <title>Chapter 6 - Calculator example v2</title></head><body> <form runat="server"> <h2>Calculator Version 2 </h2> <asp:TextBox id="txtInput1" runat="server"></asp:TextBox> <asp:Button id="btnAdd" onclick="Calc" runat="server" Text=" + "></asp:Button> <asp:Button id="btnSubtract" onclick="Calc" runat="server" Text=" - "></asp:Button> <br /> <asp:TextBox id="txtInput2" runat="server"></asp:TextBox> <asp:Button id="btnMultiply" onclick="Calc" runat="server" Text=" x "></asp:Button> <asp:Button id="btnDivide" onclick="Calc" runat="server" Text=" ÷ "></asp:Button> <br /> <strong>Answer = <asp:Label id="lblAnswer" runat="server"></asp:Label></strong> </form></body></html>
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18