Why my OnServerValidate sub is never called?


I am almost sure this code was running alright a couple of weeks ago.

I remember it was not working but then I removed the ControlToValidate property and it started to work perfectly.

But now it is broken again. Could you check my code below?

When I put a break in the validation procedure I can see the sub it is never executed. So I know the problem is not in the validation sub (which I already tested and works correctly) but in the fact that it is never executed.

Please help.

Thanks in advance.
    <asp:LinkButton ID="UpdateLinkButton" runat="server" CausesValidation="True"  CommandName="Update" Text="Update" ValidationGroup="EditItemTemplate" />
    <asp:CustomValidator ID="ComplexSaChargeCustomValidator" runat="server"
                         ErrorMessage="Charge unit, charge per unit and calculation type are required for complex charges (if one is used, all must be used)."
                         Display="Dynamic" />
<div class="Warnings">
<asp:ValidationSummary ID="ValidationSummary" runat="server"
                       ValidationGroup="EditItemTemplate" />
Sub ValidateComplexSaCharge(ByVal source As Object, ByVal arguments As ServerValidateEventArgs)
    Dim ChargeUnitNumericTextBox As WebUserControls_NumericTextBox = SaChargeGridView.Rows(SaChargeGridView.EditIndex).FindControl("ChargeUnitNumericTextBox")
    Dim ChargePerUnitNumericTextBox As WebUserControls_NumericTextBox = SaChargeGridView.Rows(SaChargeGridView.EditIndex).FindControl("ChargePerUnitNumericTextBox")
    Dim CalculationTypeDropDownList As DropDownList = SaChargeGridView.Rows(SaChargeGridView.EditIndex).FindControl("CalculationTypeDropDownList")
    If Not String.IsNullOrEmpty(ChargeUnitNumericTextBox.Text) _
    Or Not String.IsNullOrEmpty(ChargePerUnitNumericTextBox.Text) _
    Or Not String.IsNullOrEmpty(CalculationTypeDropDownList.SelectedValue) _
        If Not String.IsNullOrEmpty(ChargeUnitNumericTextBox.Text) _
        And Not String.IsNullOrEmpty(ChargePerUnitNumericTextBox.Text) _
        And Not String.IsNullOrEmpty(CalculationTypeDropDownList.SelectedValue) Then
            arguments.IsValid = True
            arguments.IsValid = False
        End If
        arguments.IsValid = True
    End If
End Sub

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Richard,

What happens if you move the CustomValidator outside the Template? Can you please try this?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
richardhaegerAuthor Commented:
Thank you, your that solved the problem.
richardhaegerAuthor Commented:
One thing I cannot understand is I have 4 other forms with custom validators inside templates and all work correctly, only this one fails. Any idea why?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.