2 Replies - 1068 Views - Last Post: 02 July 2012 - 05:42 AM Rate Topic: -----

#1 itsjimmy91  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 19-January 11

Date Validation Issue

Posted 29 June 2012 - 12:43 PM

Hey guys,

I have a simple question about validating two dates. I think it should be a lot easier than I'm making it out to be. Anyways, I have two date boxes - a Start Date and an End Date. I used a CompareValidator to make sure that the End Date was after the Start Date and that works fine. The only problem is, the page is still allowing a user to save the page, even with the incorrect dates. It's never actually going to the server and making the page invalid because a CompareValidator doesn't have this feature.

My question is how can I make the page invalid if the dates aren't valid? A simple FindControl in the code behind would probably be a good place to start, but the field is nested within another field so I'm having trouble there too...

Any suggestions?

Is This A Good Question/Topic? 0
  • +

Replies To: Date Validation Issue

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 441
  • View blog
  • Posts: 1,488
  • Joined: 28-April 09

Re: Date Validation Issue

Posted 29 June 2012 - 04:35 PM

Are you setting the ValidationGroup property of the validator and the button that submits the form?
If so, do they have the same ValidationGroup?

Also, are you using the IsValid property on the server side to check that the page is valid before saving the data? You can also call the validators Validate() method before the IsValid to ensure that the IsValid property is being updated.

CompareValidator1.Validate();
if (IsValid)
{
    // Save Data
}

Was This Post Helpful? 0
  • +
  • -

#3 itsjimmy91  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 19-January 11

Re: Date Validation Issue

Posted 02 July 2012 - 05:42 AM

Hmm.. This actually brings me to another problem that I am struggling with. Since the control is within another control, I am not able to use the FindControl method to grab the control on the server side. This makes just simply using the Validate method on the validator a challenge. I've read things that said that I will have to recursively try and find the control, but I am having trouble getting that to work also.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1