ElseIF or Case Statement?

L

Leon

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
 
D

Dan Bass

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.
 
L

Leon

How can I do these validation client side?

Dan Bass said:
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.
 
K

Kevin Spencer

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.
 
L

Leon

Thanks!
Kevin Spencer said:
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.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top