Validation Order

P

Prince

I'm trying to determine the the order of how controls get
validated. On a page, I have an <asp:panel> with some
text controls along with submit button controls and
validation on specific textbox controls.

On the same page I have a two textbox controls so user
can enter their username and password. The two buttons
below these two controls are Login + Register.

When a user first goes to the page, the panel is
invisible (visible flag = false). If the user clicks the
Register button the panel is visible and the user can
register. All the validation controls work fine.

Problem:
If the user then realizes they have already register and
want to login, they can't.

Why:
Because once the panel is visible, all the validation
controls needs to be satisfy before the form can be
submitted.

What I want to do:
When the Login button is clicked, I want to disable all
the validation controls on the page so that the username
and password can be verified against the database.

What I tried:
I tried setting each validation control, within the
loginButton_onClick() method to false.
ex. RequiredFieldValidator1.Enabled = false;

However, it seems that the validation is occuring on the
client because the onClick method for the Login button
never fires. I set a breakpoint in VS.NET to see but it
doesn't get there.

I think the solution is to make all the validation server
side instead of client-side but I don't know how to do
that. That way, when the Login Button onClick method is
executed, I can disable all the validation controls by
setting their Enabled property to false.

I've been reading the thread, "Page Validation and Submit
Problems" but that's giving me the solution.

I hope this is clear. Does anyone has any ideas?

-- Prince
 
P

Prince

I found a solution to the problem and thought i would
post it here for anyone else with the same problem.

Solution:
Set the EnableClientScript to "False" for each validation
control. This forces the control to be validated on the
client.

Then in the Submit button handler, test for page
validation.

if( Page.IsValid ){
// insert data into database
}
else{
//force validation controls to validate
Page.Validate();
}

The downside, of course, is that each Submit will be done
on the server and not the client. If there is a better
solution, please post it and let us know.

-- Prince
 
C

Craig Deelsnyder

If you look on your webserver, at the validation Javascript file (mine
is located at C:\Inetpub\wwwroot\aspnet_client\system_web\1_0_3705_0 ),
inside there is a function you can call via Javascript that will disable
or enable a validator on the clientside.

function ValidatorEnable(val, enable)

where val is your control, enable is a boolean saying whether it should
be enabled....

Note these scripts don't run (ever) on non-IE browsers.
 
P

Peter Blum

You are looking for a concept called "Validation Groups", found in the
upcoming ASP.NET 2.0.

I have developed a replacement for Microsoft's validators that includes
validation groups. You simply define a string for each group, like "login"
and "data", and assign it to the validators and buttons in a new property
called "Group". It works fully on the client-side without you writing
(hacking) code. The product is "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top