vendredi 30 juin 2017

Declared CheckBox Showing up as Undeclared in Validator

I'm getting an error saying that CheckBox1 is not declared, but it definitely is, earlier in the gridview. The background is that users are approving records in a gridview. If the record is not approved, the checkbox is unchecked. Because it was not approved, I would also like to require a comment from the user explaining why. The comment is only required if the checkbox is unchecked.

I've tried shifting the validators around, but I'm not having any luck. Is there something I'm missing? Still pretty new to asp.net. Back end is vb.net. Below is the comment field. If more is required, just let me know.

The Error:

'CheckBox1' is not declared. It may be inaccessible due to its protection level.

The Code:

<asp:TemplateField HeaderText="Comment">
    <ItemTemplate>
        <asp:TextBox ID="Comment" MaxLength="200" runat="server" Width="500px" Text='<%# Eval("Comment") %>'></asp:TextBox>
        <asp:RegularExpressionValidator 
            Display = "Dynamic" 
            ControlToValidate = "Comment" 
            ID="RegularExpressionValidator" 
            ValidationExpression = "^[a-zA-Z0-9'@&#.\s]{2,200}$"
            runat="server"  
            ForeColor="red" 
            ErrorMessage="!">
        </asp:RegularExpressionValidator>
        <%If CheckBox1.Checked = "False" then%>
            <asp:RequiredFieldValidator id="RequiredFieldValidator" runat="server"
                ControlToValidate="Comment"
                ErrorMessage="*Required"
                ForeColor="Red">
            </asp:RequiredFieldValidator>
        <%Else%>
        <%End If%>
    </ItemTemplate>
</asp:TemplateField>




Aucun commentaire:

Enregistrer un commentaire