Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello Guys, I want to know how to check textbox1.text is greater than textbox2.text
actually i am using sum value in this textboxes.

What I have tried:

C#
i want to check if textbox1.text > textbox2.text so messagebox show (Calculate);
else{
<pre lang="C#">messagebox show (try Again);</pre>

}
Posted
Updated 30-Nov-16 21:22pm

try like this

C#
int value1 ,value2;
         bool isValid1 = int.TryParse(textbox1.Text, out value1);
         bool isValid2 = int.TryParse(textbox2.Text, out value2);
         if (isValid1 && isValid2)
         {
             if (value1 > value2)
             {
                 // your code
             }
         }
         else
         {
             // invalid entry in the textbox
         }
 
Share this answer
 
Comments
ridoy 1-Dec-16 3:44am    
5ed!
Karthik_Mahalingam 1-Dec-16 4:19am    
Thank you ridoy
The CompareValidator can compare two values, for instance the values of two controls.

Visit this helpful resources.It can help you.

Validation controls in ASP.Net[^]

C# Tutorial 15: How to validate the value in a textbox - YouTube[^]
 
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