【发布时间】:2017-06-09 19:57:31
【问题描述】:
我想激活/禁用下拉列表上的必填字段,如果 radiobutton1 选中 requiredvalidator active 否则保持禁用。
html代码
<asp:RadioButton runat="server" id="radioA1" GroupName="overseas" />
<label for="radioA1">Yes </label>
<asp:RadioButton runat="server" id="radioA2" GroupName="overseas" />
<label for="radioA2">No</label>
<asp:RadioButton runat="server" id="radioA3" GroupName="overseas" />
<label for="radioA2">Not Applicable</label>
<br />
Overseas Country
<asp:DropDownList ID="DropDownList10" AppendDataBoundItems="True" CssClass="form-control mySelecBox" runat="server" DataSourceID="newCountry" DataTextField="Country" DataValueField="CountryGuid">
<asp:ListItem Text="" Value="" />
</asp:DropDownList>
<asp:SqlDataSource ID="newCountry" runat="server" ConnectionString="<%$ ConnectionStrings:umtonlineConnectionString %>" SelectCommand="SELECT [CountryGuid], [Country] FROM [countries]"></asp:SqlDataSource>
<asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" ControlToValidate="DropDownList10" Enabled="False" ErrorMessage="Oversea country required *" ForeColor="#CC0000" ValidationGroup="step1"></asp:RequiredFieldValidator>
<br />
jQuery 代码:
$(document).ready(function () {
$('#<%=radioA1.ClientID%>').click(function () {
alert("its working"); // this part work fine.
ValidatorEnable($('#<%=RequiredFieldValidator13%>'));
});
});
【问题讨论】: