テキストボックス、ラジオボタンなどのフォームがあり、ドロップダウンが特定の値に変更されたときに入力フィールドの一部に検証グループを付ける。それは可能ですか?ドロップダウンが特定の値に変更されたときに、テキストボックスに検証グループを追加します。
私はこのフォームを持っていると言うことができます。
<form>
Name:
<asp:textbox runat="server" id="nametextbox" ValidationGroup="myvalgroup"/>
<asp:RequiredFieldValidator id="nametextboxFieldValidator" runat="server" ErrorMessage="Name?" ValidationGroup="myvalgroup" ControlToValidate="nametextbox" />
Gender: <asp:RadioButtonList runat="server" ID="gender" RepeatDirection="Horizontal" ValidationGroup="myvalgroup">
<asp:ListItem Text="Select gender" Value="" Selected="True"/>
<asp:ListItem Text="Male" Value="Male"/>
<asp:ListItem Text="Female" Value="Female"/>
</asp:RadioButtonList>
<asp:RequiredFieldValidator id="genderFieldValidator" runat="server" ErrorMessage="Gender?" ValidationGroup="myvalgroup" ControlToValidate="gender" />
The answer to life the universe and everything:
<asp:textbox runat="server" id="theanswer" />
Are you finished?
<asp:RadioButtonList runat="server" ID="finished" RepeatDirection="Horizontal" onchange="add-validation-group()" >
<asp:ListItem Text="Are you done?" Value="" Selected="True"/>
<asp:ListItem Text="Yes" Value="Yes"/>
<asp:ListItem Text="No" Value="No"/>
<asp:ListItem Text="Absolutly not, i need 600 more years to think!" Value="NOT-IN-600-YEARS"/>
</asp:RadioButtonList>
<asp:button runat="server" id="submitbutton" />
</form>
分離コード
function add-validation-group()
if (finished.SelectedValue.ToString() == "Yes")
{
theanswer.Attributes.Add("ValidationGroup", "myvalgroup");
}
end
私の分離コードはすべての重複が整理が含まれていますが、ちょうど私がacomplishしたいものを表示するようにして[OK]を、codemixingのため申し訳ありません!
これを行うには、ドロップダウンリストのonchangeを入力フィールドに追加しますか?
私は正しい方向を向いてください! :)