Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
string val1="prince";<br />
string val2="PRINCE";


How to check two string values are equal and if its equal then one Confirm box must be displayed,the msg Do u Want to Continue?, or otherwise if the two string are different then confirm msg be The Two value are different, Do u want to Continue? also i need to save those value into Database.

Regards
Prince Antony G
Posted
Updated 16-Nov-11 1:01am
v5
Comments
#realJSOP 15-Nov-11 13:32pm    
Never NEVER use textspeak in a computer UI. NEVER.

Use the following code:
C#
if(val1.Equals(val2, StringComparison.InvariantCultureIgnoreCase))
{
   // they are the same
}


EDIT :
To show asp.net dialogs see here : http://www.4guysfromrolla.com/articles/021104-1.aspx[^]
 
Share this answer
 
v2
Comments
Prince Antony G 15-Nov-11 7:19am    
confirm msg box what to do?
Mehdi Gholam 15-Nov-11 7:21am    
I have updated the solution.
Prince Antony G 15-Nov-11 7:24am    
thanks for ur reply...but that link not a clear one...
Sergey Alexandrovich Kryukov 15-Nov-11 15:41pm    
My 5.
--SA
Mehdi Gholam 15-Nov-11 21:58pm    
Thanks
C#
protected void Button1_Click(object sender, EventArgs e)
{
   int comp = string.Compare(TextBox1.Text, TextBox2.Text, false);
// true - for case insensitive/ ignore case 
// false - for case sensitive 

        if (comp == 0) // If values are same
        {   
            Response.Write("<script>confirm('The Two Value Are Same. Do you Want to Continue?');</script>");
        }

        else   // If values are different
        {          
            Response.Write("<script>confirm('The Two value are different, Do you  want to Continue?');</script>");
        }
   
}
 
Share this answer
 
v2
C#
int result = string.Compare(val1, val2,true);


        if(result == 0)
        {
//Strings are equal

          }
 
Share this answer
 
v2
Comments
Prince Antony G 15-Nov-11 7:27am    
i got code for string validation but for confirm msg box what to do?
Neha Thanka 15-Nov-11 7:34am    
Try these links....
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ConfirmButton/ConfirmButton.aspx
http://www.codeproject.com/KB/webforms/NingLiangSimpleControl.aspx
C#
protected void Button1_Click(object sender, System.EventArgs e) {
        string testString1 = TextBox1.Text.ToString();
        string testString2 = TextBox2.Text.ToString();
        int result = string.Compare(testString1, testString2,true);
        Label1.Text = "";

        if(result == 0)
        {
            Label1.Text += "Two strings are equal";
        }
        else if(result == 1)
        {
            Label1.Text += "Test String1 is greater than Test String2";
        }
        else if (result == -1)
        {
            Label1.Text += "Test String1 is less than Test String2";
        }

    }
 
Share this answer
 
Comments
Prince Antony G 15-Nov-11 7:30am    
yeah ur idea is good..but i need to display the message in confirm message box..
Akhilash Mishra 15-Nov-11 7:40am    
you should try Script dialog box

like this....................
Response.Write("<script>confirm('Matching String');</script>");
or using
Response.Write("<script>alert('Matching String');</script>");
You need to use Javascript. write a function in javascript and call it on button onclientclick

JavaScript
function checkString()
{
  if (document.getElementById("txtVal1").value == document.getElementById("txtVal2").value)
      {
          if(confirm("String are same, Do you want to continue"))
             alert("you clicked yes")
          else
             alert("you clicked no")
      }
   else
      {
          if(confirm("The Two value are different, Do u want to Continue"))
             alert("you clicked yes")
          else
             alert("you clicked no")
      }
}
 
Share this answer
 
v2
Comments
Prince Antony G 16-Nov-11 1:21am    
i need to save those values into database...

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