我有许多dropDownLists和customvalidators,用于检查用户在点击保存按钮时是否从下拉列表中选择了一个选项
<asp:DropDownList runat="server" ID="ddpCountries" ClientIDMode="Static">
</asp:DropDownList>
<asp:CustomValidator ID="CustomValidator2"
ControlToValidate="ddpCountries"
ClientValidationFunction="ValidateDropDownListCountry"
ValidateEmptyText="true"
runat="server"
Text="*"
ForeColor="Red"
ValidationGroup="CheckControls" />
<asp:Button runat="server" ID="bnSavePopup" Text="Save" OnClick="BnSaveDetailsClick"
ValidationGroup="CheckControls" />
我想在javascript中创建一个客户端验证方法,它将识别从传递给javascript函数的争论中调用它的控件的名称。目前我已硬编码名称($(“#ddpCountries”)。val();)例如:
function ValidateDropDownListCountry(source, arguments) {
var SelectedValue = $("#ddpCountries").val();
if (SelectedValue != "-1") {
arguments.IsValid = true;
} else {
arguments.IsValid = false;
}
}
是否有动态方法从arguements参数推断附加到自定义验证器的输入名称?