I've been attempting to validate the contactno
control using a JavaScript function, but it doesn't seem to be triggered before the OnClick
event.
This is the JavaScript code I'm using:
<script type="text/javascript">
function validate() {
var contactno = document.getElementById('contactno').value;
if(contactno.toString.length != 7 && contactno.toString.length != 10)
{
<% result.Text = "Please enter valid phone no !!"; %>
return false;
}
else
return true;
}
</script>
Here's the HTML snippet for this:
<asp:Button runat="server" class="loginbutton" type="submit" Text="Add" OnClientClick="return validate();" OnClick="submit_Click"></asp:Button>
During debugging, I noticed that the OnClick
function gets executed without running the validate()
function first.
An update on the issue:
When I begin debugging my project, I encounter an error when setting a breakpoint in the validate()
function. The error message reads:
This breakpoint will not currently be hit. No executable code of the debugger's target code type is associated with this line.