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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CustomValidator ValidateEmptyText

Status
Not open for further replies.

Trebor100

Programmer
Mar 14, 2006
90
0
0
GB
Afternoon all,

I'm hoping that someone can save me from drink tonight by helping out on this one.

I have a CustomValidator as follows:

<asp:CustomValidator ID="customVal_1" runat="server" ValidateEmptyText="true" ControlToValidate="textBox" ClientValidationFunction="doStuff" OnServerValidate="servLocation" CssClass="validationError" ErrorMessage="error msg."></asp:CustomValidator>

The ClientValidatonFunction "doStuff" isn't fired when the the text box is empty. Any thoughts / workrounds? I'm in the tricky position of needing bespoke validation and as such requiredFieldValidators are not an option. I thought this problem had been fixed on .net 2.0 but I guess not!

For info the doStuff presently just presents an alert which I know is functioning fine.

Thanks for any help.

Rob
 
You need to post more code(dostuff) and explian what you are tying to validate
 
function doStuff(sender, args)
{
alert("moooo");
}

doStuff will ultimatley do alot. It will be checking a series of other fields to determine if this field becomes mandatory. I'd ideally like to do this without postbacks turning controls on / off etc. The validation aspect will be easy enough as long as I can get the event to fire if the field is empty.

Cheers,
Rob
 
this is a common scenario, "conditionally required" fields. An alternative to elaborate and/or complex validation is a change in how the options are presented to the user. If you created the UI to flow more like a wizard (not the wizard control, just a set of directed questions) then you can direct the user where to go and request only the information that's required. then it's just a series of simple inputs and required field validators.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
I just created a page and used your HTML. It worked for me. There must be something else in your code causing the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top