首页 > 编程 > .NET > 正文

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

2024-07-10 13:07:56
字体:
来源:转载
供稿:网友

文件:
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


<%@import namespace="calculate"%>

<script language="c#" runat="server">
public string color;
void doadd(object src, eventargs e)
{
math math=new math();
message.text=math.add(convert.toint32(a.value),convert.toint32(b.value)).tostring();
math.color=c.value;
color=math.color;

}

void dosub(object src, eventargs e)
{
math math=new math();
message.text=math.sub(convert.toint32(a.value),convert.toint32(b.value)).tostring();
math.color=c.value;
color=math.color;
}

void domul(object src, eventargs e)
{
math math=new math();
message.text=math.mul(convert.toint32(a.value),convert.toint32(b.value)).tostring();
math.color=c.value;
color=math.color;

}

</script>
<font id=cau color=<%response.write(color);%>>用asp+写得简易计算器</font>
<form runat="server">

<input id="a" runat="server"/>
<input id="b" runat="server"/>
<input id="c" runat="server"/>
<asp:button text="add" onclick="doadd" runat="server"/>
<asp:button text="sub" onclick="dosub" runat="server"/>
<asp:button text="mul" onclick="domul" runat="server"/>
</form>
result:<asp:label id=message runat="server"/>

文件:
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


<%@import namespace="calculate"%>

<script language="c#" runat="server">
public string color;
void doadd(object src, eventargs e)
{
math math=new math();
message.text=math.add(convert.toint32(a.value),convert.toint32(b.value)).tostring();
math.color=c.value;
color=math.color;

}

void dosub(object src, eventargs e)
{
math math=new math();
message.text=math.sub(convert.toint32(a.value),convert.toint32(b.value)).tostring();
math.color=c.value;
color=math.color;
}

void domul(object src, eventargs e)
{
math math=new math();
message.text=math.mul(convert.toint32(a.value),convert.toint32(b.value)).tostring();
math.color=c.value;
color=math.color;

}

</script>
<font id=cau color=<%response.write(color);%>>用asp+写得简易计算器</font>
<form runat="server">

<input id="a" runat="server"/>
<input id="b" runat="server"/>
<input id="c" runat="server"/>
<asp:button text="add" onclick="doadd" runat="server"/>
<asp:button text="sub" onclick="dosub" runat="server"/>
<asp:button text="mul" onclick="domul" runat="server"/>
</form>
result:<asp:label id=message runat="server"/>

转自:动态网制作指南 www.knowsky.com
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表