Custom validation wont trigger

F

Fendi Baba

I wrote a simple validation routine. I am trying to trigger
validation
on group of fields if an option on another radio button is selected.

Sub ValidateAdd_ServerValidate(ByVal objSource As Object, ByVal
objArgs As ServerValidateEventArgs)


if radioDbutton.SelectedItem.Value="yes" Then


If objArgs.Value = "" Then
objArgs.IsValid = False
ElseIf DropDownList1.Text = "Select A Date" Then
objArgs.IsValid = False
ElseIf RadioButtonDTime.Text = "" Then
objArgs.IsValid = False
End If
end if


End Sub


I assigned the controltovalidate to one of the fields in the group.
and the page looks like this:


TR><TD style="HEIGHT: 16px" width=770px bgColor=#e1e0ff colSpan=4>


<asp:Label id="LabelDeliverAddress" runat="server" Text="Delivery
Address " Font-Bold="True" Visible="False"></asp:Label>
<asp:CustomValidator ID="CustomValidator1"
runat="server"
ControlToValidate="TextDAPT"
OnServerValidate="ValidateAdd_ServerValidate"
ErrorMessage="CustomValidator">*</asp:CustomValidator>
</TD></TR>
<TR><TD style="WIDTH: 162px; HEIGHT: 13px" bgColor=#efffff><asp:Label
id="LabelDAPT" runat="server" Text="Address Line 1" Font-Bold="True"
Visible="False"></asp:Label></TD>
<TD colspan=3 style="WIDTH: 241px; height: 13px;"
bgColor=#ffedfe><asp:TextBox id="TextDAPT" runat="server"
Width="600px" Visible="False"></asp:TextBox></TD>
</TR>


I have ohte validation on this page, but when I submit the page, only
the custom validation wont trigger. What did I do wrong?
 
B

Bruno Piovan

You can leave the ControlToValidate property of the CustomValidator empty,
as you have a custom validation for other controls in this case, setting the
ControlToValidate property to empty, will fire the ServerValidate event. You
can also set the ValidateEmptyText property to True if you want to have the
textbox TextDAPT with visible = false or any control that requires the
validation to be fired even with empty values.

Bruno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top