locked
customvaliator control error RRS feed

  • Question

  • User1997074450 posted

    CS1061: 'default_aspx' does not contain a definition for 'ServerValidation' and no accessible extension method 'ServerValidation' accepting a first argument of type 'default_aspx' could be found (are you missing a using directive or an assembly reference?) 

    <asp:CustomValidator ID="CustomValidator1" 
                    ControlToValidate="ddlStates"
                    ClientValidationFunction="ClientValidate"
                    OnServerValidate="ServerValidation" 
                    ErrorMessage="One of the fields is required"
                    runat="server" ></asp:CustomValidator>

    void ServerValidation(object source, ServerValidateEventArgs args)
            {
                try
                {
                    // Test whether the input is selected.
                   
                    if (ddlStates.SelectedItem.Selected || !string.IsNullOrEmpty(txtTextBox.Text))
                    {
                        args.IsValid = true;
                    }
     
                }
     
                catch (Exception ex)
                {
                    args.IsValid = false;
                }
            }

    Thursday, April 29, 2021 12:23 AM

Answers

  • User-939850651 posted

    Hi vj78,

    Base on the code you provided, I created a simple demo to reproduce you problem, I think you forgot to declare the method as public.

    Something like this:

    public void ServerValidation(object source, ServerValidateEventArgs args)
    {
    // Test whether the input is selected.
    ..... }

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 29, 2021 10:12 AM