Custom validation For validating dates

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a textBox Where I type date. I want to validate it. Im using
customValidate controls. I have this function in my code behind page

void DatesValidate(object source, ServerValidateEventArgs e)
{
if (Convert.ToDateTime(e.Value) <= DateTime.Now)
{
e.IsValid = false;
this.lblAddUsers.Text = "The Proxy is already expired";
}
}

<asp:CustomValidator ID="cvEndDate" runat="server"
OnServerValidate="DatesValidate"
ControlToValidate="txtTo" ErrorMessage="error"
Display="Dynamic"></asp:CustomValidator>

It is not working it is giving the follo2ing error
'Proxy.DatesValidate(object,
System.Web.UI.WebControls.ServerValidateEventArgs)' is inaccessible due to
its protection level
 
Add protected keyword to the method, it's private by default if no access
modifier is given.

void DatesValidate...

to

protected void DatesValidate...

Just note that you can also use CompareValidator or RangeValidator for
validating date (in case it's simple validation rule). You can give it the
value (ValueToCompare property) to which TextBox's Date is compared.
 
Back
Top