Compiler does not recognize CustomValidator RRS feed

  • Question

  • User-1659346459 posted

    Split off from http://forums.asp.net/t/1596975.aspx/1?Compiler+does+not+recognize+CustomValidator#

    hey channguyen, I have the same problem. I tried to set public for code behind function but still same error. Can you please tell me how did you fix it.


    Wednesday, November 2, 2011 5:40 PM


  • User-650628323 posted

    Hi dgupta.sw,

    I am sorry I can't reproduce your issue locally.  To resolve your issue, please make sure the event handler has correct parameter types firstly. Then, please test the code below and see whether it works locally.

    In the .aspx

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <form id="Form1" runat="server">
        <asp:Label ID="Label1" runat="server" Text="name:" />
        <asp:TextBox ID="txt1" runat="server" />
        <asp:Button ID="Button1" Text="Submit" runat="server" onclick="Button1_Click" />
        <br />
        <asp:Label ID="mess" runat="server" />
        <br />
        <asp:CustomValidator ID="CustomValidator1" ControlToValidate="txt1" OnServerValidate="CustomValidator_ServerValidate"
            Text="wrong!" runat="server" />

    In the .cs

     public void CustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
            if (args.Value.Length < 8 | args.Value.Length > 16)
                args.IsValid = false;
                args.IsValid = true;
        protected void Button1_Click(object sender, EventArgs e)

    If it works well, please compare it with your code and try to find the issue. If it doesn't work, please provide more information about your code.  That will help us to continue. Thank you for your support.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 4, 2011 2:45 AM