<html>
<title>Simple 4-Function Integer Calculator</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void Page_Load ( object src, EventArgs e ) {
btnAdd.Click += new System.EventHandler ( this.Calculate );
btnSubtract.Click += new System.EventHandler ( this.Calculate );
btnMultiply.Click += new System.EventHandler ( this.Calculate );
btnDivide.Click += new System.EventHandler ( this.Calculate );
}
void Calculate ( object src, EventArgs e ) {
int op1 = Int32.Parse ( TextBox1.Text );
int op2 = Int32.Parse ( TextBox2.Text );
int result = 0;
switch ( ( ( Button ) src ) .CommandName ) {
case "Add" :
result = op1 + op2;
break;
case "Subtract" :
result = op1 - op2;
break;
case "Multiply" :
result = op1 * op2;
break;
case "Divide" :
if ( op2 > 0 )
result = op1 / op2;
else
result = 0;
break;
default:
// error handling code here.
break;
}
message.Text = result.ToString ( );
}
</script>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>Simple 4-Function Integer Calculator</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<asp:TextBox id="TextBox1" size=5 runat="server" /> <asp:TextBox id="TextBox2" size=5 runat="server" />
<p>
<asp:Button id="btnAdd" text="Add" commandname="Add" runat="server" />
<asp:Button id="btnSubtract" text="Subtract" commandname="Subtract" runat="server" />
<asp:Button id="btnMultiply" text="Multiply" commandname="Multiply" runat="server" />
<asp:Button id="btnDivide" text="Divide" commandname="Divide" runat="server" />
<p>
<asp:Label id="message" runat="server" />
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>