954,135 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ASP.NET: Problems with CustomValidator...

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:customvalidator id="CustomValidator1" runat="server" ErrorMessage="Sie msen min. 1 Telefonnummer angeben"
		Display="Static" OnServerValidate="ValidateExistanceOfPhones"></asp:customvalidator></P>
<script runat="server">
		void ValidateExistanceOfPhones(object source, ServerValidateEventArgs args)
		{
			args.IsValid = !((m_txtTelephoneNumber.Text.Length == 0) && (m_txtMobileNumber.Text.Length == 0));
		}
	</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

gicio
Newbie Poster
23 posts since Oct 2003
Reputation Points: 10
Solved Threads: 0
 

Please Enter Your Name

Your Name:

none
Newbie Poster
2 posts since Oct 2003
Reputation Points: 10
Solved Threads: 0
 

Just thinking it should be

!= as opposed to args.IsValid = !(....blah...blah)

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

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;

if m_txtTelephoneNumber.Text.Length ==0 && m_txtMobileNumber.Text.Length == 0 {
   args.IsValid = false;
}
else
{
   args.IsValid = true;
}


Sorry if my C# is not exactly correct, I am more of a VB guy than C# or C++.

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

Greetings!

function validate()
{
  var yrs_check = /[1-2][0-9]{3}$/;
	
  if(yyyy1.value=="" || yyyy2.value=="" || mthOfWage.value=="")
  {
    alert("Please fill in all the required information!");
    return false;
  }
  else
  {
    if( !yyyy1.match(yrs_check) )
    {
      alert("Please enter a the correct year format! [yyyy]");
      return false;
    }
    else if( !yyyy2.match(yrs_check) )
    {
      alert("Please enter a the correct year format! [yyyy]");
      return false;
    }
		
    return true;
}
:
:
:
:
<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.

red_evolve
Posting Whiz
313 posts since Jun 2003
Reputation Points: 53
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You