ClientSide Validation (solution to bypass "Refresh" in JavaScript)

I

IkBenHet

Hello,

Currently I am using a large input form on a website that is based on
ASP and JavaScript.

Depending on the values that are filled in by the user the forms does a
refresh and makes other input fields available to fill in. I use the
JavaScript OnChange function (=clientside) that creates a querystring
and does a refresh of the page. It works fine.

Some of the users are complaining that on slow connections this refresh
can take very long and other users find this refresh in general not a
friendly solution. And... I agree with them.

Now I am trying to migrate this website to ASP.NET and was looking for
a solution to do what I want to do: Make form fields available/visable
in the same form based on the values filled in in other fields of the
same form without the refresh.

This is want I have found:
http://www.dotnetjunkies.com/quicks...plus/samples/webforms/validate/validator2.src

But is this the way to do it? Can it also be ServerSide? I am sure that
I am not the only person in the world trying to do this. Thanks for
your advice. Please note that I am a beginner in ASP.NET.

I can not post the form because it an secured extranet page.

Thanks!
 
P

Peter Blum

When working with an ASP.NET web form, expect that when you submit, it will
post back to the same page. Your page will be structured with some code to
handle various "events". The two most common are:
- Page_Load. This method is used to setup general values on the page. It is
called every time the page is generated. For example, if you fill in a
DropDownList from a database, do it here when the page is first loaded (the
property Page.IsPostBack is false).
- "Post back event handlers" - These are methods you link to buttons and
other controls that submit the page. They fire only on post back after
Page_Load. You put your code that processes the post back. For example, in
the Button, set the Click event to your method. Then use your Click method
to save the page.
Inside the post back event handlers is where Validation goes. First, you add
the various web controls called "Validators" supplied with ASP.NET to the
web form. Attach them to the fields they evaluate. By design, they will
first attempt to validate on the client-side. But not all browsers are
supported or javascript can be disabled. So eventually the page is posted
back and you should assume the page is still not validated. So you test
Page.IsValid is true in that Click post back event method before saving. If
you find it to be false, just exit the Click event method and the same page
will be redraw, but this time, each validator with an error will be
displayed.

I encourage you to read this article: www.aspalliance.com/699 as you learn
about ASP.NET validators.
You should also consider a better validation system since Microsoft's is
very limited and causes you to write much custom code and develop hacks. I
make one called Professional Validation And More
(http://www.peterblum.com/vam/home.aspx).

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top