Click here to Skip to main content
14,979,837 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello sir,

I have three text box(tb1,tb2,tb3) where i put nominee Percentage value. And total Percentage of nominee should be 100%. Means add of three text box values ==100.

Now i want like this::=================
if (user put 100 in textbox1(tb1) then thxtbox2 & textbox3 not visible.)
if( value of textbox1(tb1)!= 100 then thxtbox2 is visible)
if( value of textbox1(tb1) + value of thxtbox2 !=100 then thxtbox3 is visible)
if ( value of textbox1(tb1) + value of thxtbox2 +value of thxtbox3 !==100, the data cannot save)

==================================
I have write the code in page load:===========
C#
tbsecondnominee.Visible = false; tbsecondper.Visible = false;
             tbthitdnominee.Visible = false; tbthitdnominee.Visible = false;


===============================
And i have write the code in protected void btsave_Click(object sender, EventArgs e)==========
C#
int a, b, c;

            a = int.Parse(tbfirstper.Text);
            b = int.Parse(tbsecondper.Text);
            c = int.Parse(tbthirdper.Text);

            if (a != 100)
            {
                tbsecondnominee.Visible = true; tbsecondper.Visible = true;

            }
            if (a + b != 100)
            {
                tbthitdnominee.Visible = true; tbthitdnominee.Visible = true;

            }

            if (a + b + c != 100)
            {
                lbper.Text = "Nominee Percentage should be 100";
                btsave.Enabled = false;
            }


==========================

But it is not working..i cant understand where is my mistake..
Please help me with the code...
Posted
Comments
PrashantSonewane 19-Apr-13 1:51am
   
1. You want total to be 100. So why you are checking sum !=100. You should be always checking sum <100.
2. Have you tried using JavaScript or Jquery as you are using ASP.NET. That's better approach for doing all validation before calling save method.
3. Using same javascript function you can manage visiblity of textboxes.
Let us know if you stuck trying out Javascript or jquery.
prodipjsr 19-Apr-13 1:54am
   
actually i have not any idea of Javascript or jquery. can u provide the code for this function??
please help me sir...
Thomas Barbare 19-Apr-13 1:56am
   
Why do you means by "it is not working" ?
Do you got an error ?

Agreed for Javascript but anyway you MUST validate server side
prodipjsr 19-Apr-13 2:01am
   
not working means when i put 50 in textbox1 then the textbox2 is not visible..
i have not any idea about javascript.. can u help me please!!!
Thomas Barbare 19-Apr-13 2:55am
   
Do you have a default value in textbox2 and textbox3 ?
Because if the value is "" you got a FormatException.
prodipjsr 19-Apr-13 3:46am
   
hello sir i am waiting for ur code..please help me..

1 solution

Hello!!
I have written this code for javascript..but it also not working..any one please help me..

<script type="text/javascript">
function TextBoxval(evt) {
var a = document.getElementById("tbfirstper").value;
var b = document.getElementById("tbsecondper").value;
var c = document.getElementById("tbthirdper").value;

if (a == 100) {
tbsecondnominee.Enabled = false; tbsecondper.Enabled = false;
bthitdnominee.Visible = false; tbthirdper.Visible = false;
}

if (a < 100)
{
tbsecondnominee.Enabled = true; tbsecondper.Enabled = true;

}
if (a + b < 100)
{
tbthitdnominee.Visible = true; tbthitdnominee.Visible = true;

}

if (a + b + c < 100)
{
lbper.Text = "Nominee Percentage should be 100";
btsave.Enabled = false;
}

}
</script>
   
Comments
   
Not an answer, should be removed.
—SA
prodipjsr 6-May-13 3:49am
   
this code also not working sir...

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