views:

262

answers:

2

There is a strange problem in my application. There is one mandatory field which we are making mandatory through Required field validator but still in few scenarios it fails. Can someone tell me what can be the possible causes. I am not able to recreate this issue.

A: 

If you are trying to validate a dropdownlist with a "Please select" option, with a value of "-1" for example, you will need to set the initial value property of the validation control to this value to ensure that another choice has been made.

Andy Rose
Why are you guessing? Besides this can be reproduced consistently, so it likely isn't the right answer.
Wim Hollebrandse
+1  A: 

If someone disables JavaScript, and you're not using Page.IsValid in your server side code, then you might encounter empty fields.

This should do:

void SubmitButton_Click(object sender, EventArgs e)
{
    if (!Page.IsValid)
        return;

    // Do form stuff
}
Thorarin
JavaScript is enabled. i have tested it in both scenarios.
AJ
It's still a good idea to check `Page.IsValid` if you're not doing so. There might be other reasons why the client side validation is not working properly, although it is actually very reliable (unless someone deliberately circumvents it).
Thorarin
@Thorarin: Agreed, definitely good practice and in this case it could well be some scenario going on where a client side error occurs (for whatever reason) and the server code ends up being executed anyway.
Wim Hollebrandse
Thanks Thorarin...
AJ