I have a required field validator and a custom validator tied to an asp:textbox within a RadGrid. The required field validator fires and displays my error message when the textbox is empty. The custom validator fires its OnServerValidate call, my code checks the text length and sets the args.IsValid = false if the text is too large.
But the Update continues to proceed and tries to update the database with some text that is too large for the database field.
The custom validator error message never displays.
What am I missing?
<EditItemTemplate>
<asp:TextBox ID="txbDescription" Style="width: 390px; margin-left: 4px;" runat="server"
TextMode="MultiLine" Rows="3" Text='<%# Bind("Description") %>' MaxLength="1000" Wrap="true" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txbDescription"
ErrorMessage="A Document description is required" Enabled="true" runat="server">
</asp:RequiredFieldValidator>
<asp:CustomValidator ID="val_txbDescription" Enabled="true" runat="server"
ErrorMessage="Description is too large. Please limit text to 1000 characters."
OnServerValidate="val_txbDescription_ServerValidate" Display="Dynamic" ControlToValidate="txbDescription">
</asp:CustomValidator>
</EditItemTemplate>
protected
void val_txbDescription_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid =
true;
if (args.Value.Length > 1000) args.IsValid = false;
}