I have some logic in a class called CustomValidation, which I now call in my C # code:
protected void EmailValidator(object source, ServerValidateEventArgs args)
{
string strInput = args.Value.Trim();
CustomValidation v = new CustomValidation();
args.IsValid = v.ValidateEmail(strInput);
}
I would rather call such methods on my ASPX page to simplify things like this:
<asp:CustomValidator OnClick="ValidateEmail" />
However, since ValidateEmail is not in the same class as the page:
'ASP.editusers_aspx' does not contain a definition for 'ValidateEmail' and no extension method 'ValidateEmail' accepting a first argument of type 'ASP.editusers_aspx' could be found (are you missing a using directive or an assembly reference?)
Is there a way to call methods from the CustomValidation class in my ASPX code? I tried the following to no avail:
<%@ Import Namespace="ThisProject.CustomValidation" %>
OnClick="<%= CustomValidation.ValidateEmail()" %>
Here is my use in context:
<asp:TextBox ID="txtEmail" runat="server" Text='<%# Bind("UserEmail") %>' MaxLength="30" />
<asp:CustomValidator ID="vldEmail" runat="server" ControlToValidate="txtEmail" ValidateEmptyText="true" OnServerValidate='<%# RetailCrime.CustomValidation.ValidateEmail((string)(txtEmail.Text)) %>' ErrorMessage='<br /><label class="invisible noplaceholder"> </label>Please enter a valid email.' Display="Dynamic" CssClass="validatormessage" />
source
share