By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,947 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,947 IT Pros & Developers. It's quick & easy.

Custom validation wont trigger

P: n/a
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?

Apr 28 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"Fendi Baba" <ef*****@epitome.com.sgwrote in message
news:11**********************@c35g2000hsg.googlegr oups.com...
>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?

Apr 28 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.