Why do I get runtime error "Control ... cannot be verified"?

I'm trying to validate a radio button using a asp:CustomValidator. The general idea is that if the button is checked, a text box must have a valid date string. I get this run-time error when the Page.IsValid statement is evaluated -

"System.Web.HttpException: Control 'SettledBtn' referenced by the ControlToValidate property of 'SettledBtnCustomValidator' cannot be validated"

The page uses a Master page, and is organized as follows:

<asp:Content ...
<asp:ScriptManager ...
<asp:Panel
<asp:UpdatePanel
<ContentTemplate>
<table> ...
    <td style="background-color: #F0F5FF">

      <asp:RadioButton ID="SettledBtn" runat="server" GroupName="BatchBtns" Text="Settled"
               CausesValidation="true" OnCheckedChanged="RadioButton_CheckedChanged"  AutoPostBack="True" />

   </td>  ....
    <td style="width: 187px">
    <asp:TextBox ID="FromDate0" runat="server"></asp:TextBox>

    <asp:CustomValidator ID="SettledBtnCustomValidator" runat="server" ErrorMessage="From date required"
    ControlToValidate="SettledBtn" ValidationGroup="DateValidators"
     OnServerValidate="SettledBtnValidator_ServerValidate"  ></asp:CustomValidator>  
...
<\table>
 </ContentTemplate>
 <Triggers>
  <asp:AsyncPostBackTrigger ControlID="FromDate0" EventName="TextChanged" />
  <asp:AsyncPostBackTrigger ControlID="ToDate0" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>

There are additional range and compare validator controls attached to the TromDate0 text box.
The code-behind is:

protected void SettledBtnValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
// 'Settled batches' option was selected, so a 'From' date is required
args.IsValid = (SettledBtn.Checked && ! String.IsNullOrEmpty(FromDate0.Text));
}

This is quite frustrating, as I really need a clue. Any ideas why a radio button '... cannot be validated'?
Thanks for your help
shellbackAsked:
Who is Participating?
 
Vee_ModCommented:
Closed, 250 points refunded.
Vee_Mod
Community Support Moderator
0
 
sabeeshCommented:
Here ControlToValidate="FromDate0" text box not button
0
 
shellbackAuthor Commented:
Thanks sabeesh - however, I just tried changing ControlToValidate to FromDate0. Compiled and published the website. After checking the settled button and leaving the FromDate0 textbox empty, I submitted the page. The desired error message 'From date required' did not appear, and the page continued on.

I misstated when the runtime error occurs - it happens immediately after I check the settled button.
0
 
shellbackAuthor Commented:
To anyone struggling with a similar problem - it seems that some controls cannot be validated with current validation controls, and radiobutton is one of them, the checkbox is another. I found a work-around suggested in the following discussion of CustomValidator controls (see http://msdn2.microsoft.com/en-us/library/9eee01cx(VS.80).aspx)

Basically, the idea is to use the CustomValidator control without setting the ControlToValidate property. The server-side event handler still executes, however, the Value property of the arguments parameter passed in to the event handler contains an empty string. In my case, this was not a problem, as I could still refer to the controls I wanted to validate.

The solution to the posted problem above:

 <asp:CustomValidator ID="SettledBtnCustomValidator" runat="server" ErrorMessage="From date required"
  ValidationGroup="DateValidators"
 OnServerValidate="SettledBtnValidator_ServerValidate"  ></asp:CustomValidator>  

Note - no ControlToValidate property.  the event handler remains the same:

protected void SettledBtnValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
// 'Settled batches' option was selected, so a 'From' date is required
args.IsValid = (SettledBtn.Checked && !String.IsNullOrEmpty(FromDate0.Text));
}

This works because I don't need to refer to args.Value in the event handler.

Please close this question

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.