Dear all
I added the validation (on server-side) for some fields of my grid. It's working fine.
But, I'd like to add, that if the field is blank/empty the validation fails as well. I found out, that when my code is running and the field is blank it's not running through the validation. Plelase find here the code of the asp and the vb I used:
As already said, it's working fine, it's just not running the CustomValidator1_ServerValidate code if the field zipcode is left blank by the user.
Does anybody has some ideas, solutions or is there anything I did wrong?
Thanks in advance for your help
Cheers
Marino
I added the validation (on server-side) for some fields of my grid. It's working fine.
But, I'd like to add, that if the field is blank/empty the validation fails as well. I found out, that when my code is running and the field is blank it's not running through the validation. Plelase find here the code of the asp and the vb I used:
<telerik:GridTemplateColumn HeaderText="Zip Code" UniqueName="TemplateColumn"> |
<EditItemTemplate> |
<asp:TextBox id="TextBox1" runat="server" Text='<%# Bind("zipcode") %>' MaxLength="4"></asp:TextBox> |
<asp:CustomValidator id="CustomValidator1" runat="server" |
ErrorMessage="please enter a zip code" |
ControlToValidate="TextBox1" |
OnServerValidate= "CustomValidator1_ServerValidate"> |
</asp:CustomValidator> |
</EditItemTemplate> |
<ItemTemplate> |
<asp:Label ID="label1" runat="server" Text='<%# Eval("zipcode") %>'></asp:Label> |
</ItemTemplate> |
</telerik:GridTemplateColumn> |
Protected Sub CustomValidator1_ServerValidate(ByVal [source] As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) |
Dim i As Integer |
Try |
i = Convert.ToInt16(args.Value) |
Catch ex As Exception |
args.IsValid = False |
End Try |
If args.Value.Length <> 4 Then |
args.IsValid = False |
End If |
End Sub 'CustomValidator1_ServerValidate |
As already said, it's working fine, it's just not running the CustomValidator1_ServerValidate code if the field zipcode is left blank by the user.
Does anybody has some ideas, solutions or is there anything I did wrong?
Thanks in advance for your help
Cheers
Marino