前台代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br/>
<br/>
<asp:Button ID="Button1" runat="server" Text="确定" onclick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label> <hr/> 你有多少钱: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br/>
我有多少钱: <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br/> <asp:Button ID="Button2" runat="server" Text="确定" onclick="Button2_Click" />
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "你输入的内容是:" + TextBox1.Text;
}
protected void Button2_Click(object sender, EventArgs e)
{
int s;
s = Convert.ToInt16(TextBox2.Text) + Convert.ToInt16(TextBox3.Text);
Label2.Text = "我们一共有:" + s.ToString()+"元";
}
}