Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client-side validation using VS 2008 CustomValidator

Status
Not open for further replies.

SunBeachWaves

Programmer
Mar 13, 2007
10
US
I'm a javascript/VS 2008 ASP.NET novice.

When I hit the command button (Edit) on the page, when I intentionally put in a wrong domain, it doesn't come up with any messages to show that the validation is working. From the tech books I have, it shouldn't be a hard thing. What am I doing wrong? I think my code is okay.

Got an .aspx form that uses a master page. In the .aspx form in the Content Place Holder I have a table with a field call txtEmail with a CustomValidator control associated with it. What I want the client-side validation to do is make sure the user puts in the company's domain for email.

Properties for the CustomValidator are set to this...
ClientValidationFunction cvCheckEmail
ControlToValidate txtEmail
Display Dynamic
Error Message Work Email only!
Text ***

fyi - isValid was not a selection in Intellisence. In a training manual I have it shows it. IsValid does come up on the server-side validation, but not here.

<script type="text/javascript">
function cvCheckEmail(src, args)
{
try {
var uInput = args.valueOf;
var uHowLong = uInput.length;
var oEmail = "mycompany.com";
var oHowLong = oEmail.length;
var odiff = 0;
var oString = "";

if (uHowLong > oHowLong) {
odiff == uHowLong - oHowLong;
oString == uInput.substring(odiff,oHowLong);
args.IsValid = (oString == oEmail);

}
catch(e) {

args.IsValid = false;
}
}

Should I be putting this code on the master page in the <head> tag area or should it be in the content place holder on the .aspx page? Tried both places, but it still doesn't work.

All feedback is greatly appreciated!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top