Client-Side Validation using ASP.NET

G

Guest

Hello Guys,

I am using the validation controls to validate my data.
But the problem is "The page is still being posted to
server".

I want to get rid of the round trips to server. Are there
any get arounds for this problem apart from the
traditional JavaScript?

I mean to say ... can we use validation controls at the
client-side ONLY and not at the server-side? I understand
that there is a ClientValidate which is costly as I have
to maintain similar code at the server too.

Thanks a bunch!
 
S

S. Justin Gengo

Anonymous,

The point of client side validation is to save a trip to the server. But
client side validation isn't guaranteed to work becuase of the wide
assortment of computers and browsers.

The way .Net handles this is to use client side validation to rule out
unecessary trips to the server for clients and browsers that it will work
for.

The validation on the server side can then be skipped by using an if/then
such as:

If Page.IsValid Then
'---your code here
End If

..Net checks if the client side validation worked and if so skips the server
side validation.

If the client side validation didn't work then the server side validation
takes over.

Also, all .net validators check if input is valid both client side and
server side (if the client validation didn't work). This means that a round
trip to the server won't take place if the client side validators are able
to run.

I hope this helps.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
J

Jos

Hello Guys,

I am using the validation controls to validate my data.
But the problem is "The page is still being posted to
server".

Do you mean that the client-side validation doesn't work?
Is this with all users?
What kind of validation controls did you use?
I want to get rid of the round trips to server. Are there
any get arounds for this problem apart from the
traditional JavaScript?

I mean to say ... can we use validation controls at the
client-side ONLY and not at the server-side? I understand
that there is a ClientValidate which is costly as I have
to maintain similar code at the server too.

Using client-side validation only is unsafe, because
malicious users have many ways to by-pass it.
Therefore, if safety is important, never trust the client-side
validation!
 
G

Guest

Dear Justin,

Thanks for your reply!

Let me explain you my concern in detail....

I have a login field which I am validating using
RequiredValidator control. Now when a user omits this
field, the ErrorMessage is displayed successfully with the
help of validator control, but the page is still being
posted back to the server.

As you said, if the validation is done successfully at the
client-side, server-side validation is skipped. But I want
to stop the postback completely if the user omits the
login field. Can this be done using ASP.NET?

Thanks in advance!
 
S

S. Justin Gengo

Anonymous,

The behaviour you would like is what .Net already does.

What browser are you testing with? If a required field is omitted then the
page typically does not post back to the server, but that behaviour doesn't
work with all browsers.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top