User Validation Error

My user control is as follows:

    <asp:TextBox ID="_txtLeadDate" runat="server" ReadOnly="true">
    </asp:TextBox>
    <asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="_txtLeadDate" ErrorMessage="You cannot select a day earlier than today!" OnServerValidate="CustomValidator2_ServerValidate" SetFocusOnError="True">&nbsp;
    </asp:CustomValidator>

and server side code:

protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args){
   if (some condition){
            args.IsValid = false;
   }else{
            args.IsValid = true;
   }
 }

But the page displays an error:

'ASP.usercontrol_preordercontrol_ascx' does not contain a definition for "CustomValidator2_ServerValidate", and the extension method "CustomValidator2_ServerValidate" cannot be found that accepts the first argument of the type "ASP.usercontrol_preordercontrol_ascx" (do you miss using the directive or using the link)

+4
source share
1 answer

Make sure the following event

protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)

UserControl (.ascx), .aspx, UserControl.

-1

Source: https://habr.com/ru/post/1570153/


All Articles