943,724 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 24031
  • ASP.NET RSS
Oct 23rd, 2003
0

ASP.NET: Problems with CustomValidator...

Expand Post »
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:

ASP.NET Syntax (Toggle Plain Text)
  1. <asp:customvalidator id="CustomValidator1" runat="server" ErrorMessage="Sie müssen min. 1 Telefonnummer angeben"
  2. Display="Static" OnServerValidate="ValidateExistanceOfPhones"></asp:customvalidator></P>


ASP.NET Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gicio is offline Offline
23 posts
since Oct 2003
Oct 23rd, 2003
0

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

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--
Reputation Points: 10
Solved Threads: 0
Newbie Poster
none is offline Offline
2 posts
since Oct 2003
Nov 4th, 2003
0

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

Just thinking it should be

!= as opposed to args.IsValid = !(....blah...blah)
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Nov 9th, 2003
0

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

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;
ASP.NET Syntax (Toggle Plain Text)
  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++.
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
May 21st, 2004
1

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

Greetings!
ASP.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 53
Solved Threads: 1
Posting Whiz
red_evolve is offline Offline
313 posts
since Jun 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: announce: Simplify .NET development with TierDeveloper
Next Thread in ASP.NET Forum Timeline: loads htm but not aspx





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC