Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi in my project am using three text boxes one is txtPurchase ,txtSales and txtProfit
when i enter in txtpurchase 5000 and txtsale 6000 so i want to display value in txtprofit 1000 without button click.can anyone suggest me how to do ?

thanks
Posted
Updated 4-Aug-18 16:18pm

C#
txtPurchase.Text="5000";
txtSales.Text="6000";


Now Genrate TxtSales Selection Changed Event(double click on textbox in design page to genrate event)
and

Write Code in That Event.
C#
protected void txtSales_TextChanged(object sender, EventArgs e)
    {
tProfit.Text=Convert.ToString(Convert.ToInt32(txtPurchase.Text)+Convert.ToInt32(txtSales.Text));
     }
 
Share this answer
 
v3
Comments
ythisbug 16-May-12 6:50am    
thanks for ur reply
Member 12938297 20-Jan-17 6:15am    
plz.. send same method for textboxes used in gridview.
Try this....

<div>
        <asp:textbox id="txt1" runat="server" autopostback="true" xmlns:asp="#unknown">
            ontextchanged="txt1_TextChanged"></asp:textbox>
        <asp:textbox id="txt2" runat="server" autopostback="true" xmlns:asp="#unknown">
            ontextchanged="txt2_TextChanged"></asp:textbox>
        <asp:textbox id="txt3" runat="server" autopostback="true" readonly="true" xmlns:asp="#unknown"></asp:textbox>
    </div>




protected void txt1_TextChanged(object sender, EventArgs e)
    {
        if((!string.IsNullOrEmpty(txt1.Text)) && (!string.IsNullOrEmpty(txt2.Text)))
        {
            txt3.Text = (Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text)).ToString();
        }
    }
    protected void txt2_TextChanged(object sender, EventArgs e)
    {
        if ((!string.IsNullOrEmpty(txt1.Text)) && (!string.IsNullOrEmpty(txt2.Text)))
        {
            txt3.Text = (Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text)).ToString();
        }
    }
 
Share this answer
 
Comments
ythisbug 16-May-12 6:50am    
thanks dude..
Member 13141795 20-Apr-17 18:21pm    
the code work just fine.
vladj91 17-Jun-19 10:07am    
worked like a charm, thank you!
You can use onTextchanged event of textbox to write the code of adding the values.
 
Share this answer
 
Comments
ythisbug 16-May-12 6:50am    
thanks
ASP.NET
<asp:textbox runat="server" id="txtOne" autopostback="true" ontextchanged="txt_TextChanged" xmlns:asp="#unknown" />
<asp:textbox runat="server" id="txtTwo" autopostback="true" ontextchanged="txt_TextChanged" xmlns:asp="#unknown" />
<asp:textbox runat="server" id="txtThree" xmlns:asp="#unknown" />


C#
protected void txt_TextChanged(object sender, EventArgs e)
{
   decimal valueOne = string.IsNullOrEmpty(txtOne.Text) ? 0 : Convert.ToDecimal(txtOne.Text);
   decimal valueTwo = string.IsNullOrEmpty(txtTwo.Text) ? 0 : Convert.ToDecimal(txtTwo.Text);

   txtThree.Text = (valueOne + valueTwo).ToString("N2");
}
 
Share this answer
 
txt_Purchase.Text="5000";
txt_Sales.Text="6000";

Now Genrate Txt_Sales textChanged Event(double click on Txt_Sales in design page to genrate event)
and

Write Code in Txt_Sales textChanged Event.
protected void txt_Sales_TextChanged(object sender, EventArgs e)
{
txt_Profit.Text=Convert.ToString(Convert.ToInt32(txt_Purchase.Text)+Convert.ToInt32(txt_Sales.Text));
}
 
Share this answer
 
protected void Button1_Click(object sender, EventArgs e)
   {

       TextBox5.Text = (Convert.ToInt64(TextBox3.Text) * Convert.ToInt64(TextBox2.Text) + Convert.ToInt64(TextBox4.Text)).ToString();
       TextBox5.Visible = true;
       Label1.Visible = true;
   }


BY-Arpit Upadhyay Airoli
Please Comment If You Have Question
 
Share this answer
 
v2
Comments
Dave Kreskowiak 4-Aug-18 23:03pm    
Asked and answered multiple times, SIX YEARS AGO.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900