Similar Query:
prevent postback of HtmlButton in C#
This is the JavaScript function I'm using:
<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 here's the corresponding markup:
<asp:Button ID="_btnSearch" runat="server" OnClientClick = "return CheckForEmptySearchBox(this.id)" />
The current setup is functioning as intended. When the text box is empty, a prompt reminds the user to provide search criteria and prevents a page reload. However, when text is entered, there is no message but still no page reload. What could be causing this issue?
UPDATE
if (boxContent == "") {
alert("Please enter search criteria");
return false;
}
else {
return true;
}
Despite the modifications, the page continues to avoid reloading.