I am trying to use a Custom Validator linked to a javascript function for a textbox for the first time. All my code is on one page (inline script). I apparently have made some errors, and I am hoping someone can help me.
Here is a example of how i am doing it now:
*the problem is that my data keeps getting sent to the server even tho it is invalid, and the error string that gets put into 'errorArea' gets pulled out when the sever sends back its response
Here is a example of how i am doing it now:
Code:
<script runat="server">
Sub Page_Load(sender As System.Object, e As System.EventArgs)
End Sub
Sub onclick1(sender As System.Object, e As System.EventArgs)
if Page.IsValid then
results.InnerHtml="Data is Valid Test"
end if
End Sub
</script>
<html><head>
<script type="text/javascript">
<!--
function go(source,args)
{
boxVal=document.getElementById('<%=box.ClientID%>').value;
boxVal2=document.getElementById('<%=box2.ClientID%>').value;
//DATA TESTS RAN HERE
if (validData!=true)
{
document.jvform.errorArea.value=errorC;//errorC would just be a string describing errors made
return false;
}
else
{return true;}
}//END FUNCTION
-->
</script></head>
<body>
<form name='jvform' method='post' runat='server'>
<asp:TextBox id="box" MaxLength="4" columns="4" Runat="server"></asp:TextBox>
<asp:TextBox id="box2" MaxLength="4" columns="4" Runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Error in Feild(s)." ClientValidationFunction="go" ValidateEmptyText="True"></asp:CustomValidator>
<textarea id='errorArea'></textArea>
<div id='results' runat='server'></div>
<asp:Button id="send1" onclick="onclick1" Runat="server" Text="Validate"></asp:Button>
</form>
</body></html>
Comment