Using customvalidator control in asp.net 1.1

  • Thread starter Thread starter settyv
  • Start date Start date
S

settyv

Hi,

I need to use customvalidator control for calculating datedifference
and need to alert if fromdate is greater than todate.Please let me know
how can i do that using this control in asp.net.


Thanks in advance,
Vishnu
 
Vishnu,

Simply handle the ServerValidate method on the CustomValidator control.
Normally the property for ControlToValidate would be pointing to the
TextBox holding the value you want to check.

However, you want to compare values from 2 controls. There is no
reason you cannot directly refer to the related controls in your event
handler.

Protected Sub cvCompareDates_ServerValidate(ByVal source As Object, _
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) _
Handles cvCompareDates.ServerValidate
Dim fromDate as String = tbFromDate.Text
Dim toDate as String = tbToDate.Text
If (IsDate(fromDate) AndAlso IsDate(toDate)) Then
args.IsValid = CDate(toDate) < CDate(fromDate)
End If
End Sub

Then you can check Page.IsValid and cvCompareDates.IsValid and trigger
the actions you want to take as appropriate.

Brennan Stehling
http://brennan.offwhite.net/blog/
 
Back
Top