C# Custom Validator - empty value

I want to validate empty textboxes (asp textboxes, not html) - the custom validator error message should appear if a textbox is empty but not by default/onload (someone clicks on it and then off it).
I've set the ValidateEmptyText property to true but this only works if I type a letter and then delete it and then move away from the textbox (Server side validation is working fine - Client-side is the problem).
If I dont type a letter and just click away, it won't show the error message- I want all errors to display if someone just 'hold tab' through the whole form, so a reminder is there if someone skips a textbox for later.

Any easy way to do this?
LVL 4
igni7eAsked:
Who is Participating?
 
igni7eConnect With a Mentor Author Commented:
great thanks, this is the only solution I've found so far:
http://stackoverflow.com/questions/926527/update-validationsummary-list-on-control-blurs
0
 
silemoneCommented:
you have to use the RequiredValidator also...or write code for the custom validator...
0
 
silemoneCommented:
using a second RequiredValidator is simplier...
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
igni7eAuthor Commented:
What do you mean by write code for the custom validator?
0
 
silemoneCommented:
that's why its custom...you can write code for it...

if you mean:

<asp:CustomValidator ...OnServerValidate = "someEvent"

then in that code, write what you want to happen in the code-behind page...
0
 
igni7eAuthor Commented:
RequiredFieldValidator is for Server-Side validation.. I need client side - that means no postback
0
 
silemoneCommented:
it also has as all of the validators do:  ClientValidationFunction

<asp:CustomValidator ...ClientValidationFunction = "someEventinJavascriptOrAnotherScriptingLanguage"
0
 
igni7eAuthor Commented:
I you don't understand my Qs..

I have a custom validator that does both client side and server side validation correctly.
The problem is, the client side validation only seems to fire on a 'onChange' event.
I need it to work when you tab onto it and tab off it.
0
 
silemoneCommented:
as i stated, it would be simplier to write a:

<asp:RequiredFieldValidator "someEventinJavascriptOrAnotherScriptingLanguage"...

they are all server controls but MS wrote them to interact with the control that they are validating without causing a page postback...they react more like ajax..that's why they were created...
0
 
silemoneCommented:
ok...customValidator is a control in aspnet...

1) do you mean you created your own validation function using javascript?  created a class for validation? a user or custom control?

2) its not working when you tab..i understand that part...
0
 
igni7eAuthor Commented:
RequiredFieldValidator doesn't have a ClientValidationFunction attirubte.. so what are you talking about???
I just tested it and it requires a submit.. only custom validator will work and i told you it calls my js function but only when the value is changed!!

I seriously think you don't have the slightest clue what you're talking about.
Please do not post any more useless comments.
0
 
silemoneCommented:
you're right about RequiredField...it has EnableClientScript...

I seriously think you don't have the slightest clue what you're talking about.
Please do not post any more useless comments.<---

control yourself young man...I know it's easy to talk rudely over anonymous medias, but that's where self discipline comes in...i'm just trying to help...there was once Sherlock, who learned a lot by Watson's errors...+ many people use terms incorrectly custom validator - is it the control or is it something you totally built yourself...
0
 
igni7eAuthor Commented:
Appologies, I just thought you were being too lazy to read my question properly and posting stupid comments to try and get points (as many people on this forum do) but I now see you that you didn't realise that I'm using the .NET CustomValidator Control - I'm using it correctly and it works.

The problem is the client-side function it calls doesn't fire unless the value in the textbox is changed.
0
 
silemoneCommented:
now...i think the I see the problem...
it appears to be that you're using the wrong event if you want validation whenever the mouse touches the textbox...

you should try using the OnBlur event...this means whenever the mouse leaves the item, this event will be called...

is this what we want? this means that validation will always occur on the textbox...
0
 
silemoneCommented:
0
 
igni7eAuthor Commented:
Yes, I need to use onBlur, but is it possible to do that using the .NET CustomValidator component?
0
 
silemoneCommented:
i'm writing an example myself...to ensure it works...before submitting..
0
 
silemoneCommented:
hmm...if you have that code...then why not integrate it...I am finding it difficult to use anything other than the OnBlur in the textbox onclient event...similar to the example without as much work...but the article seems to solve...as stated with customvalidator, onblur is not supported...unfortunately...

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.