[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# Custom Validator - empty value

Posted on 2010-01-07
18
Medium Priority
?
792 Views
Last Modified: 2012-05-08
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?
0
Comment
Question by:igni7e
  • 11
  • 7
18 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 26200098
you have to use the RequiredValidator also...or write code for the custom validator...
0
 
LVL 21

Expert Comment

by:silemone
ID: 26200102
using a second RequiredValidator is simplier...
0
 
LVL 4

Author Comment

by:igni7e
ID: 26200130
What do you mean by write code for the custom validator?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 21

Expert Comment

by:silemone
ID: 26200197
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
 
LVL 4

Author Comment

by:igni7e
ID: 26200198
RequiredFieldValidator is for Server-Side validation.. I need client side - that means no postback
0
 
LVL 21

Expert Comment

by:silemone
ID: 26200212
it also has as all of the validators do:  ClientValidationFunction

<asp:CustomValidator ...ClientValidationFunction = "someEventinJavascriptOrAnotherScriptingLanguage"
0
 
LVL 4

Author Comment

by:igni7e
ID: 26200223
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
 
LVL 21

Expert Comment

by:silemone
ID: 26200249
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
 
LVL 21

Expert Comment

by:silemone
ID: 26200274
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
 
LVL 4

Author Comment

by:igni7e
ID: 26200367
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
 
LVL 21

Expert Comment

by:silemone
ID: 26200552
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
 
LVL 4

Author Comment

by:igni7e
ID: 26200723
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
 
LVL 21

Expert Comment

by:silemone
ID: 26200843
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
 
LVL 21

Expert Comment

by:silemone
ID: 26200854
0
 
LVL 4

Author Comment

by:igni7e
ID: 26200930
Yes, I need to use onBlur, but is it possible to do that using the .NET CustomValidator component?
0
 
LVL 21

Expert Comment

by:silemone
ID: 26201132
i'm writing an example myself...to ensure it works...before submitting..
0
 
LVL 4

Accepted Solution

by:
igni7e earned 0 total points
ID: 26201410
great thanks, this is the only solution I've found so far:
http://stackoverflow.com/questions/926527/update-validationsummary-list-on-control-blurs
0
 
LVL 21

Expert Comment

by:silemone
ID: 26201965
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

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question