write these line in page load event.....
CompareValidator1.Text = "Compare unsuccessfull";
CompareValidator1.ControlToValidate = "TextBox1";
CompareValidator1.ControlToCompare = "TextBox2";
is compare validater id, TextBox1
is id of control to which you are assigning validation and TextBox2
is id of control to which you are comparing..