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.
views:
262answers:
2
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
2010-01-08 09:13:54
Why are you guessing? Besides this can be reproduced consistently, so it likely isn't the right answer.
Wim Hollebrandse
2010-01-08 09:16:57
+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
2010-01-08 09:14:16
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
2010-01-08 09:22:42
@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
2010-01-08 09:44:34