p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 (http://p2p.wrox.com/forumdisplay.php?f=389)
-   -   DDL Custom Validator (http://p2p.wrox.com/showthread.php?t=68643)

AspNetGuy June 6th, 2008 04:54 PM

DDL Custom Validator
I have created a custom validator modeling after the example in chapter 9.

The CustomValidator is in a cell with the DDL it is to validate. They are both contained in a DetailsView and the DetailsView is contained in the first step of a Wizard.

There is a JavaScript function for client side validation specified on the CustomValidator control in teh ClientValidationFunction parameter. Also there is a C# function coded and specified in the OnServerValidate parameter.

There seem to be two problems:
1) The JavaScript function is only called if I actually select an item in the DDL.

2) The ServerValidator function is only called if something is selected in the DDL.

My goal is to ensure that something is selected in the DDL.

As it is working now when the user clicks the NEXT button on the Wizard page w/o having selected anything in the DDL, the DDL is validated in the ButtonClick function with code I have there.

So how do I get the DDL validated on the client side BEFORE a post back? I am making the assumption that the ButtonClick C# function designated on the OnNextButtonClick parameter on the Wizard control is running on the server.

By the way this all works just fine if I actually select something in the DDL, but I am concerned with the occaison when the user does NOT select anything in the DDL.

Thanks in advance for all of the help.

Imar June 6th, 2008 04:58 PM

You also need a RequiredFieldValidator hooked up to the same control. Without it, the control is considered valid when no value is selected.


Imar Spaanjaars
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.

AspNetGuy June 6th, 2008 05:17 PM


Thanks again.

One would think that after 24 years of writing code, that one would remember the little things.

You are quite timely and accurate in your answers.

All times are GMT -4. The time now is 02:02 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.