| | |
ASP.NET: Problems with CustomValidator...
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2003
Posts: 23
Reputation:
Solved Threads: 0
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:
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
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)
<asp:customvalidator id="CustomValidator1" runat="server" ErrorMessage="Sie müssen min. 1 Telefonnummer angeben" Display="Static" OnServerValidate="ValidateExistanceOfPhones"></asp:customvalidator></P>
ASP.NET Syntax (Toggle Plain Text)
<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
•
•
Join Date: Oct 2003
Posts: 2
Reputation:
Solved Threads: 0
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--
--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--
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;
Sorry if my C# is not exactly correct, I am more of a VB guy than C# or C++.
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)
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++.
Greetings!
The codes are alright, I guess?
However, when I entered a wrong data format, the file "process.asp" is still loaded.
Please advice.
ASP.NET Syntax (Toggle Plain Text)
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.
![]() |
Similar Threads
- Looking for Sr. ASP .NET Developers (Software Development Job Offers)
- ASP.NET/SQL Developer/Programmer (Web Development Job Offers)
- ASP.Net perm full time programmer wanted (Web Development Job Offers)
- Front-End Developer with ASP.net needed!!! (Web Development Job Offers)
- Experience ASP.net with C# developer needed!! (Web Development Job Offers)
- ASP.Net / C# Web Developer (Web Development Job Offers)
Other Threads in the ASP.NET Forum
- Previous Thread: announce: Simplify .NET development with TierDeveloper
- Next Thread: loads htm but not aspx
| Thread Tools | Search this Thread |
.net 3.5 activexcontrol ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser businesslogiclayer button c# cac checkbox class click commonfunctions countryselector dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash formatdecimal formview gridview gudi iis javascript list listbox microsoft mono mouse mssql nameisnotdeclared news novell numerical opera panelmasterpagebuttoncontrols problem radio redirect registration relationaldatabases reportemail save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visualstudio vs2008 web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers





