Problem Facing in Server Side Validation.

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

Hi All,

I m facing problem in Server Side Validation.
For Example The Scenario is

I have two fields on the page
1 Country Dropdown List
2 Province Textbox
3 State Dropdown List

I put two validation controls on the page

1 one is RequiredFieldValidator for Province Textbox
2 second is CompareValidator for State Dropdown List

If the Country USA is selected then State should be validated whether a valid state is selected or not and Province Textbox should not validated.
If the Country other than USA is selected then Province Textbox is validated and State Dropdown List should not be validated.

But on the server when i call Page.Validate() method this validate both controls whatever is the Country is selected.
How can i disable the validation on ther server regarding of my choice.


Regards,
Muhammad Jamil Nawaz
 
M

msnews.microsoft.com

I have done it by removing the relative validator from the page.validator collection on my choice.
If any one have any other idea then please tell me

Thanks
Muhammad Jamil Nawaz
Hi All,

I m facing problem in Server Side Validation.
For Example The Scenario is

I have two fields on the page
1 Country Dropdown List
2 Province Textbox
3 State Dropdown List

I put two validation controls on the page

1 one is RequiredFieldValidator for Province Textbox
2 second is CompareValidator for State Dropdown List

If the Country USA is selected then State should be validated whether a valid state is selected or not and Province Textbox should not validated.
If the Country other than USA is selected then Province Textbox is validated and State Dropdown List should not be validated.

But on the server when i call Page.Validate() method this validate both controls whatever is the Country is selected.
How can i disable the validation on ther server regarding of my choice.


Regards,
Muhammad Jamil Nawaz
 
G

Guest

Hi Muhammad,

Removing the validator control will work or you can also set its Visible
property to false and you can also set its Enabled property to false. Either
of those would not cause a Validate event to fire during the Page.Validate.

RequiredFieldValidator1.Enabled = false;

Cheers,
Steve Goodyear
 
P

Peter Blum

I do not recommend changing the Enabled or Visible properties on the
validator to false. This will have side effects (will not write out
client-side versions of the validator and will still be disabled when the
next post back comes through.)

Microsoft designed validators with their own Validate() method and IsValid
property. When you need a validator to be disabled due to other conditions
on the page, here's how they intended you do it:
1. Set CausesValidation=false on the submit control. This will prevent
Page.Validate() from being called automatically.
2. In the Click event method, call Validate() on each validator that should
fire. You will have to develop the logic to determine if a validator will
fire or not. Once all are validated, test IsValid on each of those
validators for true and only save if all IsValids are true.

FYI: I built a replacement to Microsoft's validators that makes this easier
and supports client-side validation (on more browsers for that matter.) In
Professional Validation And More (http://www.peterblum.com/vam/home.aspx),
each of the 25 validators have a new property called "Enabler" where you
specify a rule that determines if the validator is enabled or not. As the
user changes values on the client-side, the validator will automatically
know if it should validate or not.

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

Hi All,

I m facing problem in Server Side Validation.
For Example The Scenario is

I have two fields on the page
1 Country Dropdown List
2 Province Textbox
3 State Dropdown List

I put two validation controls on the page

1 one is RequiredFieldValidator for Province Textbox
2 second is CompareValidator for State Dropdown List

If the Country USA is selected then State should be validated whether a
valid state is selected or not and Province Textbox should not validated.
If the Country other than USA is selected then Province Textbox is validated
and State Dropdown List should not be validated.

But on the server when i call Page.Validate() method this validate both
controls whatever is the Country is selected.
How can i disable the validation on ther server regarding of my choice.


Regards,
Muhammad Jamil Nawaz
 

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,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top