Possible Duplicate:
prevent postback of HtmlButton in C#
Here's my JavaScript function:
<script type = "text/javascript">
function CheckForEmptySearchBox(id) {
var index = id.substring(id.length - 1);
var boxContent = document.getElementById("contentMain__lvTSEntry__txtClientName_" + index).value;
if (boxContent == "") {
alert("Please enter search criteria");
return false;
}
}
</script>
And the markup:
<asp:Button ID="_btnSearch" runat="server" OnClientClick = "return CheckForEmptySearchBox(this.id)" />
This code is working, i.e. when the texbox is empty, the message prompt the user to enter search criteria and the javascript prevents the page to postback. However, when the user enters text, there's no message prompt but the page still doesn't postback. What's wrong?
EDIT
if (boxContent == "") {
alert("Please enter search criteria");
return false;
}
else {
return true;
}
The page is still not posting back.