在Textbox1和Textbox2中输入值后,如何使用OnChange事件立即在Label1上显示结果?
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
---------------------------------------------------------------------------------------
//Code behind
int num1;
if(!Int32.TryParse(TextBox1.Text, out num1))
{
Label1.Text = "Not a valid number";
return;
}
int num2;
if(!Int32.TryParse(TextBox2.Text, out num2))
{
Label1.Text = "Not a valid number";
return;
}
sum = num1 + num2;
Label1.Text = sum.ToString();