How to use the OnChange event to display the result on the Label1 instantly after value have enter in Textbox1 and Textbox2??
<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();
This will work for both textboxes :-
Code behind:
To use
TextChangedEvent
you need to addTextChangedEvent
event handler in your code and setAutoPostBack=true
in markupCode behind