Panel Validation

G

Guest

I have a control that simply displays a list of links. Following one of the
links doesn't post back or redirect to another page, it simply hides the
current panel and shows the one you selected... So the behavour is similar to
a tab control.

The user is expected to fill out required data on each of the panels before
pressing a submit button which is visible from all panels.

Problem I have is validating the data entered by the user. I can use built
in validators to actualy do the validation but consider this type of
situation.

The user loads the page and enters some but not all of the data on the first
panel. They then follow the link to the second panel (which sets DISPLAY:none
on the currently visible panel and DISPLAY:block on the new panel using
javascript)

If the user then enters the required data on the second panel and presses
the submit button the validators fire and fail on the first panel but the
user cannot tell because the panel is not visible.

I want to be able to do one of the following:

A) validate a panel as it loses visiblity without a postback. This way the
user must enter the data before they leave the panel. (server side validation
will still occur when the submit button is pressed but the data will already
be known good) This would be the prefered option

b) force the panel with the failed validator to be visible when the server
side validation occurs.

c) display some kind of message on the currently visible panel indicating
that there are failed validators on the first panel so the user is aware and
can correct the problem.

Any ideas would be helpful
 
S

S. Justin Gengo

Bill,

Is there a reason that you can't set the panel's visibility property from
the codebehind after a successful postback?

That way you can do your clientside validation, wrap the button's click
event code in If Page.IsValid, and only switch panels if valid entries are
made.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
G

Guest

The reason is performance. Postbacks are not very network friendly. The way
it works now changing panels is instantanious. Using postback slows things
down quite a bit and cause unnessecary network traffic
 
S

S. Justin Gengo

Bill,

But the validators will stop a postback clientside so it won't occur for any
browser that supports it. And you say you're posting back anyway upon
successful validation... So at least for the panels that need to be
validated I think that's the best solution.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

S. Justin Gengo

Bill,

A different thought if you really don't want to post back until the final
submit button is clicked. I think you'd have to cycle through each validator
and check if it's valid. You could have a subroutine for each panel that
could be called from the submit and it would loop through the validators on
that panel and then if one that isn't valid is found set that panel to
visible. If you try to do this all client side it won't work with a lot of
browsers so you may run into trouble there...


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
G

Guest

This close to what I was thinking. I could have a little piece of javascript
for each panel. When the user clicks to display one of the other panels, I
could loop through each control I want to validate and validate it. If I find
one that fails then leave the panel visible otherwise hide it and display the
one the user selected.

I sort of have this working but it is messy and not really a good solution
becasue I have to have two seperate validation routines for each control I
want to validate. Client side javascript and server side validators. I would
rather do as you suggest and make use of the validators I already have in
place.

I've tried that already and the problem I have with it is this:

Validation doesn't always occur when I change panels. Lets say I have a
panel with a textbox and a required field validator. If I open the page, the
page is valid but the textbox is blank. If I then change to another panel...
no validation. On server side validation this is not true but the client side
validation seems only to occur after a text changed event has occured. IE: I
put some text in the textbox changed then delete it...

Interesting problem... I may have to live with multiple validation routines
for each validated control.

Bill
 
G

Guest

Actually when you think about. That's not really a good solution either
because if I load the page, fill out the first panel and then hit the submit
button without selecting one of the links to display another panel validators
on the other panels would fire but not be visible and the user would have no
indication that this occured. I would also have to validate each panel on the
client when the submit button was clicked.

What might work is forget about validating when the panels change but loop
through validators on each panel when the submit button is clicked and
display the first panel I find with a failure. The validators themselves
would prevent the postback. All I have to do is find panel.

Are you a Microsoft employee? Can you point me toward a good knowledge base
article on testing validators with javascript?
 
G

Guest

You know I read somewhere on one of these forums that when you have a problem
you need to ask yourself why you need to do what you are trying to do. Then
you need to ask the same question about the answer you give yourself and keep
asking the question about your answer until you can't answer anymore. At that
point you will have come to the real problem you are trying to solve.

The bottom line with this problem is I want the end-user to have a visual
notification of any validation error that occurs regardless of the panel in
which it occurs on.

I added a ValidationSummary control to the page visible with all panels and
it 10 minutes my problem is over.

I thank you very much for your time Justin. You have definitly helped me
think this problem through.
 
S

S. Justin Gengo

Bill,

No, I'm not MS. And sorry, but I don't know of a good article for this.

What I'm fearful of is that by the time your done you may actually end up
using more processing power than the post backs would have taken. I see what
you're going for, and I hope you get it working.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top