用ASP+实现一个简单的计算器(适合入门者)

废话少说,直接进入主题.

文件:
Calculate.aspx
bin/Calculate.cs
bin/Calculate.bat

步骤:
1.Calculate.cs

namespace Calculate
{
using System;
public class math {

public String _color;
public int Add(int a,int b)
{
return a+b;
}

public int Sub(int a,int b)
{
return a-b;
}

public int Mul(int a,int b)
{
return a*b;
}
public String Color
{
get {
return _color;
}
set {
_color=value;
}
}

}
}

2.Calculate.bat

csc /t:library /out:Calculate.dll Calculate.cs

3.执行Calculate.bat

4.Calculate.aspx

1@Import NameSpace="Calculate"
 1<script language="c#" runat="server">   
 2public String color;   
 3void DoAdd(Object Src, EventArgs E)   
 4{   
 5math math=new math();   
 6Message.Text=math.Add(Convert.ToInt32(A.Value),Convert.ToInt32(B.Value)).ToString();   
 7math.Color=C.Value;   
 8color=math.Color;   
 9  
10}   
11  
12void DoSub(Object Src, EventArgs E)   
13{   
14math math=new math();   
15Message.Text=math.Sub(Convert.ToInt32(A.Value),Convert.ToInt32(B.Value)).ToString();   
16math.Color=C.Value;   
17color=math.Color;   
18}   
19  
20void DoMul(Object Src, EventArgs E)   
21{   
22math math=new math();   
23Message.Text=math.Mul(Convert.ToInt32(A.Value),Convert.ToInt32(B.Value)).ToString();   
24math.Color=C.Value;   
25color=math.Color;   
26  
27}   
28  
29</script>
1<font ```="" color="```" id="Cau" response.write(color);="">用ASP+写得简易计算器</font>
1<form runat="server">
2<input id="A" runat="server"/>
3<input id="B" runat="server"/>
4<input id="C" runat="server"/>
5<asp:button onclick="DoAdd" runat="server" text="Add"></asp:button>
6<asp:button onclick="DoSub" runat="server" text="Sub"></asp:button>
7<asp:button onclick="DoMul" runat="server" text="Mul"></asp:button>
8</form>

Result:

1<asp:label id="Message" runat="server"></asp:label>

5.总结
实在太烂,希望高手多多指教.(无限真诚)

Published At
Categories with Web编程
Tagged with
comments powered by Disqus