我认为我试图做的事情是微不足道的,但结果却给我带来了很大的麻烦。这是情况。
我有两个单选按钮(使用 RadButton 实现)和一个 RadTextBox。我想检查客户端,然后在选择两个无线电按钮之一时提交表单,即RadTextbox并非空(例如,第一个)。我已经使用了 CustomValidator 并将 ValidateEmptyText="True" 设置为没有运气。代码摘录如下:
<asp:Panel runat="server" ID="Panel1">
<table>
<tr>
<td class="auto-style5">
<telerik:RadButton ID="rdBtnIndividual" runat="server" AutoPostBack="False" GroupName="rdEmplrType"
Text="Individual" ToggleType="Radio" OnClientCheckedChanged="rdBtnPhysical_CheckedChanged"
UseSubmitBehavior="False">
<ToggleStates>
<telerik:RadButtonToggleState PrimaryIconCssClass="rbToggleRadioChecked" />
<telerik:RadButtonToggleState PrimaryIconCssClass="rbToggleRadio" />
</ToggleStates>
</telerik:RadButton>
</td>
<td>
<telerik:RadButton ID="rdBtnLegal" runat="server" AutoPostBack="False" GroupName="rdEmplrType" Text="Legal Entity"
ToggleType="Radio" OnClientCheckedChanged="rdBtnLegal_CheckedChanged" UseSubmitBehavior="False">
<ToggleStates>
<telerik:RadButtonToggleState PrimaryIconCssClass="rbToggleRadioChecked" />
<telerik:RadButtonToggleState PrimaryIconCssClass="rbToggleRadio" />
</ToggleStates>
</telerik:RadButton>
</td>
</tr>
<tr>
<td class="auto-style5">
<label>Name:</label>
</td>
<td>
<telerik:RadTextBox ID="txtName" Runat="server" EmptyMessage="Name" LabelWidth="64px" Resize="None" Width="160px" DisabledStyle-BackColor="Silver">
</telerik:RadTextBox>
</td>
<td><asp:RequiredFieldValidator ID="THIS_IS_WORKING" ControlToValidate="txtName"
runat="server" ErrorMessage="<img src='images/Exclamation.png' Title='Required Field'/>" >
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style5">
<label>Father's Name</label>
</td>
<td style="width:100px">
<telerik:RadTextBox ID="txtFathersName" Runat="server" EmptyMessage="Father's Name" LabelWidth="64px" Resize="None" Width="160px" DisabledStyle-BackColor="Silver">
</telerik:RadTextBox>
</td>
<td>
<asp:CustomValidator runat="server" ID="NOT_WORKING_VALIDATOR" ControlToValidate="txtFathersName" ValidateEmptyText="True"
ClientValidationFunction="RequiredIfIndividual"
ErrorMessage="<img src='images/Exclamation.png' Title='Required Field'/>" EnableClientScript="True">
</asp:CustomValidator>
</td>
</tr>
</table>
</asp:Panel>
javascript如下:
<script type="text/javascript">
function RequiredIfIndividual(sender, args) {
var chkBoxIndividual = $find("<%=rdBtnIndividual.ClientID%>");
chkBoxIndividual = $telerik.toButton(chkBoxIndividual);
if (chkBoxIndividual.get_checked()) {
if (args.Value == "") {
args.IsValid = false;
}
else {
args.IsValid = true;
}
} else {
args.IsValid = true;
}
}
</script>