0

我的页面上有一个RequiredFieldValidator文本框,并且想要启用或禁用 . 因为我想检查所需Option的内容是否true适用RequiredFieldValidator于该文本框。

<asp:TextBox ID="txtReference" runat="server" ></asp:TextBox> 
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtReference"
                                                                Display="None" ErrorMessage="Reference Should Not Blank !" ValidationGroup="Ac"></asp:RequiredFieldValidator>
                                                            <ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender9" runat="server"
                                                                Enabled="True" TargetControlID="RequiredFieldValidator1">
                                                            </ajaxToolkit:ValidatorCalloutExtender>
                                                             <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender7" runat="server" CompletionInterval="100"
                                                                DelimiterCharacters="" EnableCaching="False" Enabled="True" FirstRowSelected="True"
                                                                MinimumPrefixLength="1" ServiceMethod="GetReference" ServicePath="" TargetControlID="txtReference">
                                                            </ajaxToolkit:AutoCompleteExtender>

我尝试这样做但不起作用的代码

if (_clients.ReferenceRequired == true)
                {
                    RequiredFieldValidator1.Enabled = true;
                    AutoCompleteExtender7.Enabled = true;
                }
                else
                {
                    RequiredFieldValidator1.Enabled = false;
                    AutoCompleteExtender7.Enabled = false;
                }

但这在我的页面上找不到我的控件,我该怎么做?

4

1 回答 1

1

尝试将 ValidationGroup 设置为与页面上的正常值不同的值

   if (_clients.ReferenceRequired == true)
   {
        RequiredFieldValidator1.ValidationGroup = "Ac";
        AutoCompleteExtender7.ValidationGroup= "Ac";
    }
    else
    {
        RequiredFieldValidator1.ValidationGroup = "none";
        AutoCompleteExtender7.ValidationGroup = "none";
    }
于 2013-01-14T08:55:46.793 回答