By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

javascript function for customvalidator

P: 4
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:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <script runat="server">
  3.   Sub Page_Load(sender As System.Object, e As System.EventArgs)
  4.   End Sub
  5.   Sub onclick1(sender As System.Object, e As System.EventArgs)
  6.     if Page.IsValid then
  7.       results.InnerHtml="Data is Valid Test"
  8.     end if
  9.   End Sub
  10. </script>
  11. <html><head>
  12. <script type="text/javascript">
  13. <!--
  14. function go(source,args)
  15. {
  16.   boxVal=document.getElementById('<%=box.ClientID%>').value;
  17.   boxVal2=document.getElementById('<%=box2.ClientID%>').value;
  18.  
  19. //DATA TESTS RAN HERE
  20.   if (validData!=true)
  21.   {
  22.     document.jvform.errorArea.value=errorC;//errorC would just be a string describing errors made
  23.     return false;
  24.   }
  25.   else
  26.   {return true;}
  27. }//END FUNCTION
  28. -->
  29. </script></head>
  30. <body>
  31. <form name='jvform' method='post' runat='server'>
  32.   <asp:TextBox id="box" MaxLength="4" columns="4" Runat="server"></asp:TextBox>
  33.   <asp:TextBox id="box2" MaxLength="4" columns="4" Runat="server"></asp:TextBox>
  34.   <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Error in Feild(s)." ClientValidationFunction="go" ValidateEmptyText="True"></asp:CustomValidator>
  35.   <textarea id='errorArea'></textArea>
  36.   <div id='results' runat='server'></div>
  37.   <asp:Button id="send1" onclick="onclick1" Runat="server" Text="Validate"></asp:Button>
  38. </form>
  39. </body></html>
  40.  
*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
Jul 28 '12 #1

✓ answered by str4nge

nevermind. i changed it to args.IsValid instead of return, and it works.

Share this Question
Share on Google+
1 Reply


P: 4
nevermind. i changed it to args.IsValid instead of return, and it works.
Jul 28 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.