Custom Validation in ASP.NET
aspx source sode:
<p>
Name:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox1"
ErrorMessage="character must be greater than 6 and lesser than 10"></asp:CustomValidator>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Join" type="submit"
Width="62px" />
</p>
ServerValidation Code:
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
If (Len(TextBox1.Text) < 6 Or Len(TextBox1.Text) > 10) Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub
Happy coding :)
if the code doesn't work, comment below.
<p>
Name:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox1"
ErrorMessage="character must be greater than 6 and lesser than 10"></asp:CustomValidator>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Join" type="submit"
Width="62px" />
</p>
ServerValidation Code:
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
If (Len(TextBox1.Text) < 6 Or Len(TextBox1.Text) > 10) Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub
Happy coding :)
if the code doesn't work, comment below.
Comments
Post a Comment