Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
How to disply percentage in textbox8? where txt6 got automatically and txt7 is 500 box value given in asp.net c# without taking anything between when click on txtbox 8 it should come.

C#
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{


    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void lnkB_Click(object sender, EventArgs e)
    {
        lbl1.Visible = lblMes.Visible=lbl2.Visible = lbl3.Visible = lbl4.Visible = lbl5.Visible = lbl6.Visible = lbl7.Visible = lbl8.Visible =lbl9.Visible = txt1.Visible = txt2.Visible = txt3.Visible = txt4.Visible = txt5.Visible = txt6.Visible = txt7.Visible = lbl10.Visible=btnS.Visible=btnC.Visible=txt8.Visible=true;
    }
    protected void txt1_TextChanged(object sender, EventArgs e)
    {
        if ((!string.IsNullOrEmpty(txt1.Text)) && (!string.IsNullOrEmpty(txt2.Text)) && (!string.IsNullOrEmpty(txt3.Text)) && (!string.IsNullOrEmpty(txt4.Text)) && (!string.IsNullOrEmpty(txt5.Text)))
        {
            txt6.Text = (Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text) + Convert.ToInt32(txt3.Text) + Convert.ToInt32(txt4.Text) + Convert.ToInt32(txt5.Text)).ToString();
        }
    }

    protected void txt2_TextChanged(object sender, EventArgs e)
    {
        if ((!string.IsNullOrEmpty(txt1.Text)) && (!string.IsNullOrEmpty(txt2.Text)) && (!string.IsNullOrEmpty(txt3.Text)) && (!string.IsNullOrEmpty(txt4.Text)) && (!string.IsNullOrEmpty(txt5.Text)))
        {
            txt6.Text = (Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text) + Convert.ToInt32(txt3.Text) + Convert.ToInt32(txt4.Text) + Convert.ToInt32(txt5.Text)).ToString();
        }

    }
    protected void txt3_TextChanged(object sender, EventArgs e)
    {
        if ((!string.IsNullOrEmpty(txt1.Text)) && (!string.IsNullOrEmpty(txt2.Text)) && (!string.IsNullOrEmpty(txt3.Text)) && (!string.IsNullOrEmpty(txt4.Text)) && (!string.IsNullOrEmpty(txt5.Text)))
        {
            txt6.Text = (Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text) + Convert.ToInt32(txt3.Text) + Convert.ToInt32(txt4.Text) + Convert.ToInt32(txt5.Text)).ToString();
        }


    }
    protected void txt4_TextChanged(object sender, EventArgs e)
    {
        if ((!string.IsNullOrEmpty(txt1.Text)) && (!string.IsNullOrEmpty(txt2.Text)) && (!string.IsNullOrEmpty(txt3.Text)) && (!string.IsNullOrEmpty(txt4.Text)) && (!string.IsNullOrEmpty(txt5.Text)))
        {
            txt6.Text = (Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text) + Convert.ToInt32(txt3.Text) + Convert.ToInt32(txt4.Text) + Convert.ToInt32(txt5.Text)).ToString();
        }


    }
    protected void txt5_TextChanged(object sender, EventArgs e)
    {
        if ((!string.IsNullOrEmpty(txt1.Text)) && (!string.IsNullOrEmpty(txt2.Text)) && (!string.IsNullOrEmpty(txt3.Text)) && (!string.IsNullOrEmpty(txt4.Text)) && (!string.IsNullOrEmpty(txt5.Text)))
        {
            txt6.Text = (Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text) + Convert.ToInt32(txt3.Text) + Convert.ToInt32(txt4.Text) + Convert.ToInt32(txt5.Text)).ToString();
        }

    }

    protected void txt8_TextChanged1(object sender, EventArgs e)
    {

    }
}





h
Posted
Updated 12-Oct-11 20:34pm
v2
Comments
Vivek Krishnamurthy 13-Oct-11 2:39am    
Suggest, simplify your question
sandesh.mumbai 13-Oct-11 2:44am    
please explain in details what u want to do?

1 solution

First things first. Go back to the VS designer and change the names of your Text boxes to something that describes what that do: tbOrderQuantity or whatever, rather than txt1. It will make your code a whole lot more readable.

Then, replace the handlers for the first five text boxes with a common handler: at the moment you have five identical routines, which means that you must remember to make the same change in all of them if you find a problem, or if your specification changes.

After that, look at putting some error checking / capture in there, so your program won't just cause an exception and crash out the first time the user hits the wrong key.

Finally, work out what you actually want to do: you know how to get a text box content, you know how to convert datatypes, and you know how to set a new textbox content. So working out a percentage shouldn't be difficult. As it is, we don't know exactly what you are trying to achieve.
 
Share this answer
 

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