Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello my dear friends,

I want to compare and validate two textboxes
============================================

on my webpage i have two textboxes, user must not enter same values in both textboxes. if he enter same values in both textboxes. it must show error.

Note : Values must be different in two textboxes.

Please help, thanks in advance
Posted
Comments
[no name] 27-Aug-13 7:29am    
Help with what? You did not ask any question or describe any kind of a problem.
Anuja Pawar Indore 27-Aug-13 8:08am    
try this or you are looking for client side if(String1.Equals(String2,StringComparison.InvariantCultureIgnoreCase))

 
Share this answer
 
C#
protected void button1_Click(object sender, EventArgs e)
       {
           if (TextBox1.Text.Trim() == "" || TextBox2.Text.Trim() == "")
               lblMessage.Text = "One or more input field is empty,Please enter values";

           if (TextBox1.Text.Trim() == TextBox2.Text.Trim())
               lblMessage.Text = "Please enter different values";

       }
 
Share this answer
 
Comments
Siva Hyderabad 4-Apr-14 3:31am    
+5
Siva Hyderabad 21-Aug-14 2:45am    
Hello karthik , do you remember me?
busy na?
Karthik_Mahalingam 11-Nov-14 5:19am    
Hi Siva
Here the exact solution you are asking for.

This will work exactly for you.

http://www.w3schools.com/aspnet/showaspx.asp?filename=demo_comparevalidator2[^]
 
Share this answer
 
C#
string a =TextBox2.Text;
       string b = TextBox3.Text;
        if (a.Equals(b))
        {
//your first action
}
else {
//your second action
}
 
Share this answer
 
C#
Below function will do it for you

function StringCompare()
{
    var string1 = document.getElementById("TextBox1").value;
    var string2 = document.getElementById("TextBox2").value;

    if(string1 == string2)
    {
        alert("Both values are same.");
    }
    else
       {
        alert("Values are different.");
    }
    return false;
}
//in the button event call the javascript
<asp:Button id="Button1" OnClientClick="StringCompare();" runat="server" Text="Button1"/>
 
Share this answer
 
Try
C#
if(TextBox1.Text.Equals(TextBox2.Text, StringComparison.Ordinal))
{
  //Don't enter same value
}
else
{
  //Continue your work
}
 
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