Solved

vb.net if...then statement help

Posted on 2007-11-26
4
529 Views
Last Modified: 2009-12-16
Ok, I know this is a simple question...so I hope I can get a quick answer.

I'm trying to do a if, then statement that checks for one criteria, and has multiple responses based upon the criteria. The problem is, only ONE response is given, while I want THREE actions to take place. The following is the code;

        If ddlLocation.Text = "Lake Lure, NC" Then
            imgLocation.ImageUrl = "~/halc/images/lakeOff.jpg"
            lblContact.Visible = True
            lblLocPhone.Text = "(877)743-2589"
        ElseIf ddlLocation.Text = "Stanton, KY" Then
            imgLocation.ImageUrl = "~/halc/images/StantonOff.jpg"
            lblContact.Visible = True
            lblLocPhone.Text = "(877)220-0005"
        ElseIf ddlLocation.Text = "Plant City, FL" Then
            imgLocation.ImageUrl = "~/halc/images/PlantOff.jpg"
            lblContact.Visible = True
            lblLocPhone.Text = "(866)757-1771"
        ElseIf ddlLocation.Text = "Fallbrook, CA" Then
            imgLocation.ImageUrl = "~/halc/images/fallbrookOff.jpg"
            lblContact.Visible = True
            lblLocPhone.Text = "(760)728-1064"
        Else
            imgLocation.ImageUrl = "~/halc/images/NoLoc.jpg"
            lblContact.Visible = False
            lblLocPhone.Text = ""
        End If

I am hoping someone can tell me what I'm missing. I know it's simple (and I'll feel stupid once someone answers the question) I just don't know it.
0
Comment
Question by:hacresIT
  • 2
4 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 20350790
Can you elaborate on what you mean by "only ONE response is given, while I want THREE actions to take place"?  If you're referring to having 3 statements inside each branch of the "if" statement, what you have will execute all 3.
0
 
LVL 4

Expert Comment

by:edwardq
ID: 20350813
Use ddlLocation.SelectedItem.Text  instead of ddlLocation.Text.
0
 
LVL 1

Author Comment

by:hacresIT
ID: 20350940
Ok, as it is, when an item is selected, the only thing that currently happens is the image changes as directed by the code;  imgLocation.ImageUrl = "~/halc/images/PlantOff.jpg"

The asp.net lables DO NOT change as directed by the statements given;

 lblContact.Visible = True
 lblLocPhone.Text = "(866)757-1771"


0
 
LVL 4

Accepted Solution

by:
edwardq earned 50 total points
ID: 20351017
Are you setting up the lblContact.Visable = false in the Page_Load? if so you need to check to see if its a this is a page postback.  If so, skip the lblContact and the LocPhone.Text = "".
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now