I have a bit of Jquery (sort of mixed with traditional javascript) to check a textbox. On my sample asp page, there is a button, a textbox and on code behind there is a button_click event. What I am trying to get is, when someone clicked on the button, if the textbox is empty, they will see a alert box. When there is a value, they will see a confirm dialog box. My code does most of the job but when the user see confirm dialog box, and cancel, the server side code got executed.
What am I missing here?
Thanks in advance.
$(document).ready(function () {
$("#Button1").click(function (e) {
var a = $("#TextBox1").val();
if (jQuery.trim(a).length > 0) {
confirm('To confirm click OK ');
}
else {
alert("Empty");
e.preventDefault();
}
});
});