In asp button there is a property called OnClientClick there u can specify the java script function like given below
<asp:button id="btnSave" tabIndex="32" runat="server" CssClass="btn" OnClientClick = "return compare()"Text="Save"></asp:button>
in ur javascipt function now u can write the compare function like given below
<script language="javascript" type="text/javascript">
function compare() {
var txt1 = document.getElementById('txt1').value; // textbox 1 ID is txt1
var txt2 = document.getElementById('txt2').value; // textbox 2 ID is txt2
if (txt1 == txt2) {
alert("both are same");
}
else {
alert("both are different");
}
}
</script>
Check this out.