一个中继器的内部条件的RequiredFieldValidator [英] Conditional RequiredFieldValidator inside of a repeater

查看:111
本文介绍了一个中继器的内部条件的RequiredFieldValidator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有持有单选按钮列表,文本框和一个RequiredFieldValidator控制中继器。在RadioButtonList拥有以下:

I have a repeater that holds a Radio button list, a textbox and a requiredfieldvalidator control. The Radiobuttonlist holds the following:

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

文本框设置为允许用户输入一些正当理由,他们的回答和的RequiredFieldValidator确保该文本框是不是空的,很简单。但是范围已经改变了一点,现在客户希望的RequiredFieldValidator只火如果答案是不是M。

The textbox is set to allow the user to input some justification for their answer, and the requiredfieldvalidator makes sure that the textbox is not empty, simple enough. However the scope has changed a bit and now the client wants the requiredfieldvalidator to fire ONLY if the answer is not "M".

我已经尝试设置一个Load方法的验证,但是,当验证加载它根本不知道答案是什么在RBL,因为它是在用户应答前被解雇。我不认为我可以做回发,因为该转发器是一个模式弹出式内处理,如果我做回发,我不知道会发生什么。如何将我的验证器设置为false,仅当用户选择不是会见?

I have tried setting a Load method for the validator, however when the validator loads it has no idea what the answer is in the RBL because it is fired before the user answers. I do not think that I can do a postback, because the repeater is handled within a Modal popup and if I do a postback I am not sure what will happen. How can I set my validator to false only if the user selects something other than "Meets"?

推荐答案

试试这个:

Java脚本:

<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:

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 + "');");
        }
    }

这篇关于一个中继器的内部条件的RequiredFieldValidator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆