Conditional RequiredFieldValidator inside Relay

I have a repeater in which there is a list of radio buttons, a text field and a control for the required parameter. Radiobuttonlist contains the following:

Meets (Value M)
Above (Value A)
Below (Value B)
N/A (Value(N/A)

The text field is configured to allow the user to enter any justification for his answer, and the required identifier confirms that the text field is not empty, simple enough. However, the scope of changes has changed a bit, and now the client wants the required validator parameter to work ONLY if the answer is not "M".

I tried to set the Load method for the validator, however, when the check loader does not know that the answer is in RBL, because it starts before the user answers. I don’t think I can do the postback because the repeater is being processed inside the modal popup and if I do the postback I’m not sure what will happen. How can I set my validator to false only if the user selects something other than "Meets"?

0
source share
1 answer

try the following:

java script:

<script type="text/javascript">
    function UpdateValidator(radioID, validatorid) {
        //enabling the validator only if the checkbox is checked
        var enableValidator = $("#" + radioID).is(":checked");          
        ValidatorEnable(validatorid, enableValidator);
    }
</script>

Cs code:

protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            RadioButton rd = e.Item.FindControl("myRb") as RadioButton;
            RequiredFieldValidator rfv = e.Item.FindControl("myRfv") as RequiredFieldValidator;
            // you can just pass "this" instead of "myDiv.ClientID" and get the ID from the DOM element
            rd.Attributes.Add("onclick", "UpdateValidator('" + rd.ClientID + "','" + rfv.ClientID + "');");
        }
    }
+1
source

All Articles