Click here to Skip to main content
15,887,746 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionDate and time validation are not working. Any ideas? <Resolved> Pin
samflex5-Jul-14 12:54
samflex5-Jul-14 12:54 
AnswerRe: Date and time validation are not working. Any ideas? Pin
Richard Deeming7-Jul-14 3:02
mveRichard Deeming7-Jul-14 3:02 
GeneralRe: Date and time validation are not working. Any ideas? Pin
samflex7-Jul-14 4:21
samflex7-Jul-14 4:21 
GeneralRe: Date and time validation are not working. Any ideas? Pin
Richard Deeming7-Jul-14 4:27
mveRichard Deeming7-Jul-14 4:27 
GeneralRe: Date and time validation are not working. Any ideas? Pin
samflex7-Jul-14 4:36
samflex7-Jul-14 4:36 
QuestionRe: Date and time validation are not working. Any ideas? Pin
Richard Deeming7-Jul-14 4:45
mveRichard Deeming7-Jul-14 4:45 
AnswerRe: Date and time validation are not working. Any ideas? Pin
samflex7-Jul-14 4:51
samflex7-Jul-14 4:51 
GeneralRe: Date and time validation are not working. Any ideas? Pin
Richard Deeming7-Jul-14 5:17
mveRichard Deeming7-Jul-14 5:17 
OK, there were a few typos in my post, which should now be corrected:
  • Missing "f" from hourDiff within the if (endMinutes < startMinutes) block;
  • Missing break statements from the switch clauses;
  • jQuery selectors should be select[name$=...] instead of select[id$=...] due to changes in ASP.NET 4.0 ID generation;


I've updated my post with the Javascript code which should now work. The VB.NET code should look something like this:
VB.NET
Protected Sub ValidateDuration(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
    Dim validator As Control = DirectCast(sender, Control)
    Dim row As Control = validator.NamingContainer

    Dim startHour As Integer = Integer.Parse(DirectCast(row.FindControl("startHour"), DropDownList).SelectedValue)
    Dim startMinutes As Integer = Integer.Parse(DirectCast(row.FindControl("startMinutes"), DropDownList).SelectedValue)
    Dim startAmPm As String = DirectCast(row.FindControl("startAmPm"), DropDownList).SelectedValue

    Select Case startAmPm
        Case "AM"
            If startHour = 12 Then
                startHour = 0
            End If
            
        Case "PM"
            If startHour <> 12 Then
                startHour += 12
            End If
            
        Case Else
            args.IsValid = True
            Return
    End Select

    Dim endHour As Integer = Integer.Parse(DirectCast(row.FindControl("endHour"), DropDownList).SelectedValue)
    Dim endMinutes As Integer = Integer.Parse(DirectCast(row.FindControl("endMinutes"), DropDownList).SelectedValue)
    Dim endAmPm As String = DirectCast(row.FindControl("endAmPm"), DropDownList).SelectedValue

    Select Case endAmPm
        Case "AM"
            If endHour = 12 Then
                endHour = 0
            End If
            
        Case "PM"
            If endHour <> 12 Then
                endHour += 12
            End If
            
        Case Else
            args.IsValid = True
            Return
    End Select

    Dim hourDiff As Integer = endHour - startHour
    If endMinutes < startMinutes Then
        hourDiff -= 1
    End If

    args.IsValid = hourDiff >= 4
End Sub


The validator won't raise an error. Instead, as with any other validator control, the Page.IsValid property will return False. So your update method should look something like:
VB.NET
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
    If Page.IsValid Then
        ' Update the database...
    End If
End Sub




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Date and time validation are not working. Any ideas? Pin
samflex7-Jul-14 5:31
samflex7-Jul-14 5:31 
AnswerRe: Date and time validation are not working. Any ideas? Pin
Kornfeld Eliyahu Peter7-Jul-14 3:31
professionalKornfeld Eliyahu Peter7-Jul-14 3:31 
Questionhow to check if user is fan of a facebook page using javascript? Pin
Meax3-Jul-14 6:50
Meax3-Jul-14 6:50 
AnswerRe: how to check if user is fan of a facebook page using javascript? Pin
zeGeek9-Jul-14 14:28
zeGeek9-Jul-14 14:28 
AnswerRe: how to check if user is fan of a facebook page using javascript? Pin
Vfleitao14-Jul-14 22:27
Vfleitao14-Jul-14 22:27 
Questionauto refresh marker on google map with directions Pin
popsompong1-Jul-14 0:10
popsompong1-Jul-14 0:10 
QuestionAngular JS Pin
chauhanvatsal30-Jun-14 20:40
chauhanvatsal30-Jun-14 20:40 
AnswerRe: Angular JS Pin
Kornfeld Eliyahu Peter30-Jun-14 21:41
professionalKornfeld Eliyahu Peter30-Jun-14 21:41 
AnswerRe: Angular JS Pin
gaupoit3-Jul-14 5:27
gaupoit3-Jul-14 5:27 
Questionhow to get data from json url ? Pin
Tamil Purushothaman29-Jun-14 20:43
Tamil Purushothaman29-Jun-14 20:43 
AnswerRe: how to get data from json url ? Pin
Graham Breach29-Jun-14 22:18
Graham Breach29-Jun-14 22:18 
Questionmouseout isn't firing Pin
ThetaClear29-Jun-14 1:34
ThetaClear29-Jun-14 1:34 
AnswerRe: mouseout isn't firing Pin
ThetaClear29-Jun-14 23:21
ThetaClear29-Jun-14 23:21 
AnswerRe: mouseout isn't firing Pin
Kornfeld Eliyahu Peter30-Jun-14 1:16
professionalKornfeld Eliyahu Peter30-Jun-14 1:16 
GeneralRe: mouseout isn't firing Pin
ThetaClear30-Jun-14 1:26
ThetaClear30-Jun-14 1:26 
GeneralRe: mouseout isn't firing Pin
ThetaClear30-Jun-14 3:38
ThetaClear30-Jun-14 3:38 
AnswerRe: mouseout isn't firing Pin
Kornfeld Eliyahu Peter30-Jun-14 3:43
professionalKornfeld Eliyahu Peter30-Jun-14 3:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.