Custom validation For validating dates

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
 
T

Teemu Keiski

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top