用asp.net在三个文本框输出前两个文本框的和
时间: 2023-12-14 19:37:09 浏览: 75
感谢您的提问!以下是用ASP.NET实现输出前两个文本框的和的代码:
```
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
int num1 = Convert.ToInt32(Request.Form["num1"]);
int num2 = Convert.ToInt32(Request.Form["num2"]);
int sum = num1 + num2;
TextBox3.Text = sum.ToString();
}
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<label for="num1">Number 1:</label>
<input type="text" id="num1" name="num1" />
</div>
<div>
<label for="num2">Number 2:</label>
<input type="text" id="num2" name="num2" />
</div>
<div>
<label for="sum">Sum:</label>
<input type="text" id="sum" name="sum" ReadOnly="True" />
</div>
<div>
<asp:Button runat="server" ID="btnSubmit" Text="Calculate" />
</div>
</form>
</body>
</html>
```
这段代码为网页添加了三个文本框和一个按钮。当用户点击按钮时,通过Page_Load事件,获取前两个文本框中的值,进行计算并输出到第三个文本框中。
阅读全文