Currently, I am working on incorporating JavaScript validations for mandatory fields within a form located in an ASP.NET Web Application.
The process involves obtaining the ClientID of the control that requires validation, extracting its value, and checking if it is empty:
function validate()
{
if(document.getElementById('<%=textbox1.clientID %>').value=="")
{
alert('This field is mandatory');
return false;
}
}
I have successfully tested this validation logic when placed directly within the page and triggered upon a button click event.
However, moving the code to an external JavaScript file resulted in unexpected behavior. The function does not execute as intended and instead throws an error message stating 'object not found at document.getElementByid() line'.