Thursday 24 May 2012

Adding Two text box value and redirecting it to third text box value

In design Page


 <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server" OnTextChanged="text2_changed" AutoPostBack="true"></asp:TextBox>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
    </div>
    </form>

In code behind


    protected void text2_changed(object sender, EventArgs e)
    {
        try
        {

            int x = Convert.ToInt32(TextBox1.Text);
            int y = Convert.ToInt32(TextBox2.Text);

            int z = x + y;

            TextBox3.Text = z.ToString();
        }
        catch (Exception ex)
        {
            Label1.Text = "There seems to be an Exception.  !!" + ex.ToString();
        }
    }





No comments:

Post a Comment