I have an ASP.NET button on a webpage:
<asp:Button ID="TickButton" runat="server" OnClientClick="SelectSome()" Text="Tick" />
and a JavaScript function:
function SelectSome() {
var id = document.getElementById("ctl00_ContentPlaceHolder1_txtSelectSome").value;
if (isNaN(id)==false)
{
var frm = document.forms[0], j = 0;
for (i = 0; i < frm.elements.length; i++) {
if (frm.elements[i].type == "checkbox" && j < id) {
frm.elements[i].checked = true;
j++;
}
}
}
else
{
alert("You must enter a number.")
}
return false;
}
When I click on the button; the JavaScript function runs and then the webpage refreshes. Why does the webpage refresh? According to this link; returning FALSE should stop the webpage from refreshing: Stop page reload of an ASP.NET button