简体   繁体   中英

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.

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
}

如果您尝试使用“请选择”选项(例如,值为“ -1”)验证下拉列表,则需要将验证控件的初始值属性设置为此值,以确保已选择其他选项。制作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM