ElseIF or Case Statement?

Discussion in 'ASP .Net' started by Leon, Dec 16, 2004.

  1. Leon

    Leon Guest

    Is there anyway I could clean-up all these ElseIF statements with a
    select/case or is this the best that can be done ("I can't think of a better
    way")?

    Private Sub Update_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Update.Click

    If Page.IsValid Then

    If Me.NewEmailAddress.Text = "" And Me.NewPassword.Text = "" Then

    Me.CustomDataCheck.IsValid = False

    Me.CustomDataCheck2.IsValid = False

    ElseIf Me.NewEmailCheck.Text <> "" And Me.NewEmailAddress.Text = "" Then

    Me.CompEmailCheck.IsValid = False

    ElseIf Me.NewPasswordCheck.Text <> "" And Me.NewPassword.Text = "" Then

    Me.CompPasswordCheck.IsValid = False

    ElseIf Me.NewEmailAddress.Text = context.Session("Email") Then

    Me.CustomEmailCheck.IsValid = False

    Me.CustomEmailCheck.ErrorMessage = "Email update failed - Email Address " &
    _

    Me.NewEmailAddress.Text & " is already registered to your account."

    Me.CustomEmailCheck.Text = "Opps Already In Use By You!"

    ElseIf Me.NewEmailAddress.Text <> "" And Me.NewPassword.Text <> "" Then

    UpdateAccount(Me.NewEmailAddress.Text, Me.NewPassword.Text)

    ElseIf Me.NewEmailAddress.Text <> "" Then

    UpdateAccount(Me.NewEmailAddress.Text, Me.CurrentPassword.Text)

    ElseIf Me.NewPassword.Text <> "" Then

    UpdateAccount(context.Session("Email"), Me.NewPassword.Text)

    End If

    End If

    End Sub
     
    Leon, Dec 16, 2004
    #1
    1. Advertising

  2. Leon

    Dan Bass Guest

    Leon,

    It looks like a load of page validation which could be done client side with
    some validators... This would only allow a postback (and hence Update_Click)
    to fire once the Validators have been passed, eliminating the need for the
    checking to be done in this method.

    Thanks.
    Dan.

    "Leon" <> wrote in message
    news:...
    > Is there anyway I could clean-up all these ElseIF statements with a
    > select/case or is this the best that can be done ("I can't think of a
    > better
    > way")?
    >
    > Private Sub Update_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles Update.Click
    >
    > If Page.IsValid Then
    >
    > If Me.NewEmailAddress.Text = "" And Me.NewPassword.Text = "" Then
    >
    > Me.CustomDataCheck.IsValid = False
    >
    > Me.CustomDataCheck2.IsValid = False
    >
    > ElseIf Me.NewEmailCheck.Text <> "" And Me.NewEmailAddress.Text = "" Then
    >
    > Me.CompEmailCheck.IsValid = False
    >
    > ElseIf Me.NewPasswordCheck.Text <> "" And Me.NewPassword.Text = "" Then
    >
    > Me.CompPasswordCheck.IsValid = False
    >
    > ElseIf Me.NewEmailAddress.Text = context.Session("Email") Then
    >
    > Me.CustomEmailCheck.IsValid = False
    >
    > Me.CustomEmailCheck.ErrorMessage = "Email update failed - Email Address "
    > &
    > _
    >
    > Me.NewEmailAddress.Text & " is already registered to your account."
    >
    > Me.CustomEmailCheck.Text = "Opps Already In Use By You!"
    >
    > ElseIf Me.NewEmailAddress.Text <> "" And Me.NewPassword.Text <> "" Then
    >
    > UpdateAccount(Me.NewEmailAddress.Text, Me.NewPassword.Text)
    >
    > ElseIf Me.NewEmailAddress.Text <> "" Then
    >
    > UpdateAccount(Me.NewEmailAddress.Text, Me.CurrentPassword.Text)
    >
    > ElseIf Me.NewPassword.Text <> "" Then
    >
    > UpdateAccount(context.Session("Email"), Me.NewPassword.Text)
    >
    > End If
    >
    > End If
    >
    > End Sub
    >
    >
     
    Dan Bass, Dec 17, 2004
    #2
    1. Advertising

  3. Leon

    Leon Guest

    How can I do these validation client side?

    "Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
    news:e6%23n%...
    > Leon,
    >
    > It looks like a load of page validation which could be done client side
    > with some validators... This would only allow a postback (and hence
    > Update_Click) to fire once the Validators have been passed, eliminating
    > the need for the checking to be done in this method.
    >
    > Thanks.
    > Dan.
    >
    > "Leon" <> wrote in message
    > news:...
    >> Is there anyway I could clean-up all these ElseIF statements with a
    >> select/case or is this the best that can be done ("I can't think of a
    >> better
    >> way")?
    >>
    >> Private Sub Update_Click(ByVal sender As System.Object, ByVal e As
    >> System.EventArgs) Handles Update.Click
    >>
    >> If Page.IsValid Then
    >>
    >> If Me.NewEmailAddress.Text = "" And Me.NewPassword.Text = "" Then
    >>
    >> Me.CustomDataCheck.IsValid = False
    >>
    >> Me.CustomDataCheck2.IsValid = False
    >>
    >> ElseIf Me.NewEmailCheck.Text <> "" And Me.NewEmailAddress.Text = "" Then
    >>
    >> Me.CompEmailCheck.IsValid = False
    >>
    >> ElseIf Me.NewPasswordCheck.Text <> "" And Me.NewPassword.Text = "" Then
    >>
    >> Me.CompPasswordCheck.IsValid = False
    >>
    >> ElseIf Me.NewEmailAddress.Text = context.Session("Email") Then
    >>
    >> Me.CustomEmailCheck.IsValid = False
    >>
    >> Me.CustomEmailCheck.ErrorMessage = "Email update failed - Email Address "
    >> &
    >> _
    >>
    >> Me.NewEmailAddress.Text & " is already registered to your account."
    >>
    >> Me.CustomEmailCheck.Text = "Opps Already In Use By You!"
    >>
    >> ElseIf Me.NewEmailAddress.Text <> "" And Me.NewPassword.Text <> "" Then
    >>
    >> UpdateAccount(Me.NewEmailAddress.Text, Me.NewPassword.Text)
    >>
    >> ElseIf Me.NewEmailAddress.Text <> "" Then
    >>
    >> UpdateAccount(Me.NewEmailAddress.Text, Me.CurrentPassword.Text)
    >>
    >> ElseIf Me.NewPassword.Text <> "" Then
    >>
    >> UpdateAccount(context.Session("Email"), Me.NewPassword.Text)
    >>
    >> End If
    >>
    >> End If
    >>
    >> End Sub
    >>
    >>

    >
    >
     
    Leon, Dec 17, 2004
    #3
  4. A Select Case statement only works when you are comparing against a single
    value. If the logic in your code represents the way you want it to run, I
    believe you've come up with about the best you can do here.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Neither a follower
    nor a lender be.

    "Leon" <> wrote in message
    news:...
    > Is there anyway I could clean-up all these ElseIF statements with a
    > select/case or is this the best that can be done ("I can't think of a

    better
    > way")?
    >
    > Private Sub Update_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles Update.Click
    >
    > If Page.IsValid Then
    >
    > If Me.NewEmailAddress.Text = "" And Me.NewPassword.Text = "" Then
    >
    > Me.CustomDataCheck.IsValid = False
    >
    > Me.CustomDataCheck2.IsValid = False
    >
    > ElseIf Me.NewEmailCheck.Text <> "" And Me.NewEmailAddress.Text = "" Then
    >
    > Me.CompEmailCheck.IsValid = False
    >
    > ElseIf Me.NewPasswordCheck.Text <> "" And Me.NewPassword.Text = "" Then
    >
    > Me.CompPasswordCheck.IsValid = False
    >
    > ElseIf Me.NewEmailAddress.Text = context.Session("Email") Then
    >
    > Me.CustomEmailCheck.IsValid = False
    >
    > Me.CustomEmailCheck.ErrorMessage = "Email update failed - Email Address "

    &
    > _
    >
    > Me.NewEmailAddress.Text & " is already registered to your account."
    >
    > Me.CustomEmailCheck.Text = "Opps Already In Use By You!"
    >
    > ElseIf Me.NewEmailAddress.Text <> "" And Me.NewPassword.Text <> "" Then
    >
    > UpdateAccount(Me.NewEmailAddress.Text, Me.NewPassword.Text)
    >
    > ElseIf Me.NewEmailAddress.Text <> "" Then
    >
    > UpdateAccount(Me.NewEmailAddress.Text, Me.CurrentPassword.Text)
    >
    > ElseIf Me.NewPassword.Text <> "" Then
    >
    > UpdateAccount(context.Session("Email"), Me.NewPassword.Text)
    >
    > End If
    >
    > End If
    >
    > End Sub
    >
    >
     
    Kevin Spencer, Dec 17, 2004
    #4
  5. Leon

    Leon Guest

    Thanks!
    "Kevin Spencer" <> wrote in message
    news:%...
    >A Select Case statement only works when you are comparing against a single
    > value. If the logic in your code represents the way you want it to run, I
    > believe you've come up with about the best you can do here.
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > Neither a follower
    > nor a lender be.
    >
    > "Leon" <> wrote in message
    > news:...
    >> Is there anyway I could clean-up all these ElseIF statements with a
    >> select/case or is this the best that can be done ("I can't think of a

    > better
    >> way")?
    >>
    >> Private Sub Update_Click(ByVal sender As System.Object, ByVal e As
    >> System.EventArgs) Handles Update.Click
    >>
    >> If Page.IsValid Then
    >>
    >> If Me.NewEmailAddress.Text = "" And Me.NewPassword.Text = "" Then
    >>
    >> Me.CustomDataCheck.IsValid = False
    >>
    >> Me.CustomDataCheck2.IsValid = False
    >>
    >> ElseIf Me.NewEmailCheck.Text <> "" And Me.NewEmailAddress.Text = "" Then
    >>
    >> Me.CompEmailCheck.IsValid = False
    >>
    >> ElseIf Me.NewPasswordCheck.Text <> "" And Me.NewPassword.Text = "" Then
    >>
    >> Me.CompPasswordCheck.IsValid = False
    >>
    >> ElseIf Me.NewEmailAddress.Text = context.Session("Email") Then
    >>
    >> Me.CustomEmailCheck.IsValid = False
    >>
    >> Me.CustomEmailCheck.ErrorMessage = "Email update failed - Email Address "

    > &
    >> _
    >>
    >> Me.NewEmailAddress.Text & " is already registered to your account."
    >>
    >> Me.CustomEmailCheck.Text = "Opps Already In Use By You!"
    >>
    >> ElseIf Me.NewEmailAddress.Text <> "" And Me.NewPassword.Text <> "" Then
    >>
    >> UpdateAccount(Me.NewEmailAddress.Text, Me.NewPassword.Text)
    >>
    >> ElseIf Me.NewEmailAddress.Text <> "" Then
    >>
    >> UpdateAccount(Me.NewEmailAddress.Text, Me.CurrentPassword.Text)
    >>
    >> ElseIf Me.NewPassword.Text <> "" Then
    >>
    >> UpdateAccount(context.Session("Email"), Me.NewPassword.Text)
    >>
    >> End If
    >>
    >> End If
    >>
    >> End Sub
    >>
    >>

    >
    >
     
    Leon, Dec 17, 2004
    #5
  6. Leon

    Dan Bass Guest

    Do a search on validators and asp.net...

    I found this:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/pdc_userinput.asp
    [beware of line wraps]

    let me know if you get stuck


    "Leon" <> wrote in message
    news:%...
    > How can I do these validation client side?
    >
    > "Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
    > news:e6%23n%...
    >> Leon,
    >>
    >> It looks like a load of page validation which could be done client side
    >> with some validators... This would only allow a postback (and hence
    >> Update_Click) to fire once the Validators have been passed, eliminating
    >> the need for the checking to be done in this method.
    >>
    >> Thanks.
    >> Dan.
    >>
    >> "Leon" <> wrote in message
    >> news:...
    >>> Is there anyway I could clean-up all these ElseIF statements with a
    >>> select/case or is this the best that can be done ("I can't think of a
    >>> better
    >>> way")?
    >>>
    >>> Private Sub Update_Click(ByVal sender As System.Object, ByVal e As
    >>> System.EventArgs) Handles Update.Click
    >>>
    >>> If Page.IsValid Then
    >>>
    >>> If Me.NewEmailAddress.Text = "" And Me.NewPassword.Text = "" Then
    >>>
    >>> Me.CustomDataCheck.IsValid = False
    >>>
    >>> Me.CustomDataCheck2.IsValid = False
    >>>
    >>> ElseIf Me.NewEmailCheck.Text <> "" And Me.NewEmailAddress.Text = "" Then
    >>>
    >>> Me.CompEmailCheck.IsValid = False
    >>>
    >>> ElseIf Me.NewPasswordCheck.Text <> "" And Me.NewPassword.Text = "" Then
    >>>
    >>> Me.CompPasswordCheck.IsValid = False
    >>>
    >>> ElseIf Me.NewEmailAddress.Text = context.Session("Email") Then
    >>>
    >>> Me.CustomEmailCheck.IsValid = False
    >>>
    >>> Me.CustomEmailCheck.ErrorMessage = "Email update failed - Email Address
    >>> " &
    >>> _
    >>>
    >>> Me.NewEmailAddress.Text & " is already registered to your account."
    >>>
    >>> Me.CustomEmailCheck.Text = "Opps Already In Use By You!"
    >>>
    >>> ElseIf Me.NewEmailAddress.Text <> "" And Me.NewPassword.Text <> "" Then
    >>>
    >>> UpdateAccount(Me.NewEmailAddress.Text, Me.NewPassword.Text)
    >>>
    >>> ElseIf Me.NewEmailAddress.Text <> "" Then
    >>>
    >>> UpdateAccount(Me.NewEmailAddress.Text, Me.CurrentPassword.Text)
    >>>
    >>> ElseIf Me.NewPassword.Text <> "" Then
    >>>
    >>> UpdateAccount(context.Session("Email"), Me.NewPassword.Text)
    >>>
    >>> End If
    >>>
    >>> End If
    >>>
    >>> End Sub
    >>>
    >>>

    >>
    >>

    >
    >
     
    Dan Bass, Dec 17, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Franks
    Replies:
    2
    Views:
    1,258
    Steve Franks
    Jun 10, 2004
  2. simonced

    elseif problem

    simonced, Jun 2, 2006, in forum: Ruby
    Replies:
    7
    Views:
    137
    simonced
    Jun 3, 2006
  3. 7stud 7stud

    elseif v. elsif ??

    7stud 7stud, Mar 7, 2007, in forum: Ruby
    Replies:
    83
    Views:
    851
    Samantha
    Mar 13, 2007
  4. planetthoughtful

    Newbie: if / elseif

    planetthoughtful, Mar 14, 2007, in forum: Ruby
    Replies:
    10
    Views:
    222
    Chad Perrin
    Mar 16, 2007
  5. fl
    Replies:
    6
    Views:
    368
    HT-Lab
    Feb 28, 2013
Loading...

Share This Page