ASP.NET: Problems with CustomValidator...

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2003
Posts: 23
Reputation: gicio is an unknown quantity at this point 
Solved Threads: 0
gicio gicio is offline Offline
Newbie Poster

ASP.NET: Problems with CustomValidator...

 
0
  #1
Oct 23rd, 2003
Hi!

I have a litte problem with my CustomValidator.


What my CustomValidator should do:
The CustomValidator should check if 2 textboxes are empty..
if yes he should diplay a message.


This is my code:

  1. <asp:customvalidator id="CustomValidator1" runat="server" ErrorMessage="Sie müssen min. 1 Telefonnummer angeben"
  2. Display="Static" OnServerValidate="ValidateExistanceOfPhones"></asp:customvalidator></P>


  1. <script runat="server">
  2. void ValidateExistanceOfPhones(object source, ServerValidateEventArgs args)
  3. {
  4. args.IsValid = !((m_txtTelephoneNumber.Text.Length == 0) && (m_txtMobileNumber.Text.Length == 0));
  5. }
  6. </script>



the calidator check ValidateExistanceOfPhones. but when args.IsValid = false the message isn't
shown. What is the problem??!
Make I something wrong?

2. quastion: is it possible to check the state of the 2 textboxes on the client side?
when YES how?



best regards,


gicio
Reply With Quote Quick reply to this message  
Join Date: Oct 2003
Posts: 2
Reputation: none is an unknown quantity at this point 
Solved Threads: 0
none none is offline Offline
Newbie Poster

Re: ASP.NET: Problems with CustomValidator...

 
0
  #2
Oct 23rd, 2003
I am posting this reply in hopes that someone will be kind enough to return the favor. My question is posted right below yours. Anyway, here's the solution to your problem. You said you would be able to validate via client side, correct? Well, here's a working form with validation (writting in client-side javascript). Enjoy.

--copy below here--
<html>
<head>
<script language="JavaScript">

<!--

function validate_form ( )
{
valid = true;

if ( document.contact_form.contact_name.value == "" )
{
alert ( "Please fill in the 'Your Name' box." );
valid = false;
}

return valid;
}

//-->

</script>
<title>Form Validator</title>
</head>

<body>

<form name="contact_form" method="post"
action="test.html"
onSubmit="return validate_form ( );">

<h1>Please Enter Your Name</h1>

<p>Your Name: <input type="text" name="contact_name"></p>
<p><input type="submit" name="send" value="Send Details"></p>

</form>

</body>
</html>
--copy above here--
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: ASP.NET: Problems with CustomValidator...

 
0
  #3
Nov 4th, 2003
Just thinking it should be

!= as opposed to args.IsValid = !(....blah...blah)
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: ASP.NET: Problems with CustomValidator...

 
0
  #4
Nov 9th, 2003
args.IsValid = !((m_txtTelephoneNumber.Text.Length == 0) && (m_txtMobileNumber.Text.Length == 0));

Is not really the way to go. Why are you having a boolean value come from a condition logic statement?

I would do something like this;
  1. if m_txtTelephoneNumber.Text.Length ==0 && m_txtMobileNumber.Text.Length == 0 {
  2. args.IsValid = false;
  3. }
  4. else
  5. {
  6. args.IsValid = true;
  7. }

Sorry if my C# is not exactly correct, I am more of a VB guy than C# or C++.
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: ASP.NET: Problems with CustomValidator...

 
1
  #5
May 21st, 2004
Greetings!
  1. function validate()
  2. {
  3. var yrs_check = /[1-2][0-9]{3}$/;
  4.  
  5. if(yyyy1.value=="" || yyyy2.value=="" || mthOfWage.value=="")
  6. {
  7. alert("Please fill in all the required information!");
  8. return false;
  9. }
  10. else
  11. {
  12. if( !yyyy1.match(yrs_check) )
  13. {
  14. alert("Please enter a the correct year format! [yyyy]");
  15. return false;
  16. }
  17. else if( !yyyy2.match(yrs_check) )
  18. {
  19. alert("Please enter a the correct year format! [yyyy]");
  20. return false;
  21. }
  22.  
  23. return true;
  24. }
  25. :
  26. :
  27. :
  28. :
  29. <form method="post" action="process.asp" onSubmit="return validate()" >

The codes are alright, I guess?
However, when I entered a wrong data format, the file "process.asp" is still loaded.
Please advice.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC