asp.net 做的计算器 怎样让它计算时不刷新整个页面
这是我的代码:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
string str1 = TextBox1.Text;
if (str1.ToString() == "")
str1 = "0";
string str2 = TextBox2.Text;
if (str2.ToString() == "")
str2 = "0";
int num = int.Parse(str1) + int.Parse(str2);
TextBox3.Text = num.ToString();
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
string str1 = TextBox1.Text;
string str2 = TextBox2.Text;
int num = int.Parse(str1) + int.Parse(str2);
TextBox3.Text = num.ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
return;
}
}
</script>
<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" OnTextChanged="TextBox1_TextChanged" AutoPostBack="True"></asp:TextBox>
+
<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" AutoPostBack="True"></asp:TextBox>
=
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></div>
</form>
</body>
</html>
我在TextBox1 和TextBox2 输入数据后,会把结果直接算出放到位 TextBox3 里,但是会刷新一下页面,能不能不让它刷新,有什么办法/