Force check group check if condition is not met

I have a group of text fields that require validation of the fields. Obviously, they all have the same validation group name. I have a checkbox for the terms of service that need to be checked before clicking the submit button for virtually anything.

Is there any C # code that says that if this check box is not selected, the check failed?

Or is there a better way?

edit: I added a special validator and used it in my code. Does not work.

protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
    args.IsValid = false;
    if (cbxTerms.Checked)
        args.IsValid = true;
}
+5
source share
5 answers

, . , req. 99999px . # , , textbox.text = "; checkbox check , , , textbox.text =" 1";. , ,

: .

0

, JavaScript. , submit. , , , true, false, . JavaScript , , , , .

0

, , ,

if (!cbxTerms.Checked) 
{requiredlabel.text="*";
return;}

, ,

0

. http://www.4guysfromrolla.com/articles/121907-1.aspx http://www.4guysfromrolla.com/articles/092006-1.aspx

I think this is a slightly different approach, but I used it a while ago to handle a similar situation, and it seems to work very well.

0
source

you can even prevent postback if the checkbox is unchecked.

Button1.Attributes["onclick"] =
        "if (!$get('" + CheckBox1.ClientID + "').checked){alert('Agree with us,plz!');return false;}";

why do all things check if it can be prevented :)

or if you are trying to make the group invalid tou to do this, you can get your own client side check:

function myStartUpValidation(group){
    var result=true;
    //Page_ClientValidate(group); to validate group
    for (var i = 0; i < Page_Validators.length; i++) { 
        if(Page_Validators[i].validationGroup==group){
        try{
            ValidatorValidate(Page_Validators[i]); //this forces validation in all groups
            if(Page_Validators[i].isvalid==false){result=false;}
            }catch(err){}
        }
    }
    return result;
}

or additional validator ...

0
source

All Articles