0

How can i check if a text in of one textbox is equal to or greater than the text in another textbox ?

I have tried range validator and compare validator but cant get anything to work.

Swornim Nepal
  • 13
  • 2
  • 7
  • Did you heard about custom validator use client side scripts to validate this sort of things... https://msdn.microsoft.com/en-IN/library/9eee01cx(v=vs.71).aspx – Sankar Dec 07 '16 at 05:47
  • what do you want to compare string or number? – Manoj Naik Dec 07 '16 at 05:47
  • 1
    I want to compare numbers can you please post the code. @ManojNaik – Swornim Nepal Dec 07 '16 at 05:49
  • 1
    Don't let others write code for you. – mad_manny Dec 07 '16 at 06:38
  • @SwornimNepal It seems that you are using .net framework 4.5 .JFYI, CompareValidator Control will work upto .net framework 4. If you want to use this control then you have to use .net framework 4 or else find any other alternatives of CompareValidator control. – Manoj Naik Dec 07 '16 at 06:51

3 Answers3

0

C#:

double a = Convert.ToDouble(TextBox1.Text);
double b = Convert.ToDouble(TextBox2.Text);

if (a == b)
{
    // Do things
}

ASP: https://forums.asp.net/t/1793666.aspx?Compare+two+numeric+text+box

Essigwurst
  • 555
  • 10
  • 24
0

You need to use CompareValidator, and fill the ControlToValidate and ControlToCompare with your Textboxes IDs as below :

<asp:CompareValidator 
       ID="cvEndYear2" Operator="GreaterThanEqual" runat="server"
       ValidationGroup="Validate" ControlToValidate="YourFirstTextBoxID"  
       ControlToCompare="YourSecondTextBoxID" ErrorMessage="" SetFocusOnError="true">
</asp:CompareValidator>

You can have a look at this and this .

Community
  • 1
  • 1
Null
  • 511
  • 5
  • 22
0
        if (double.Parse(TextBox1.Text) > double.Parse(TextBox2.Text))
        {
            // 1 greater than 2
        }
        else
        {
            // 1 less than or equal to 2
        }
Terry Lennox
  • 29,471
  • 5
  • 28
  • 40