Search code examples
c#asp.netrequiredfieldvalidator

What are the conditions when sometimes Required field validators fails in C#?


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.


Solution

  • 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
    }