ASP CustomValidator, advancing to postback after error

后端 未结 3 682
死守一世寂寞
死守一世寂寞 2021-01-22 19:55

I have an ASP .NET page with ASP validators (Required Field, Regular Expression,...) plus java script functions for additional validation (for example, to check if second date b

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-22 20:34

    I solved this problem by creating a variable:

     Boolean fieldIsValid = true;
    

    and in the custom validating expression method I would change the value if arguments weren't true:

    if(args.IsValid == false)
                {
                    fieldIsValid = false;
                }
                else
                {
                    fieldIsValid = true;
                }
    

    Then, I also put that in the submit click method:

    protected void submit_Click(object sender, EventArgs e)
            {
                if (fieldIsValid)
                {
                    //submit my things
                }
            }
    

提交回复
热议问题