[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

vb.net if...then statement help

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
hacresIT
Asked:
hacresIT
  • 2
1 Solution
 
mastooCommented:
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
 
edwardqCommented:
Use ddlLocation.SelectedItem.Text  instead of ddlLocation.Text.
0
 
hacresITAuthor Commented:
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
 
edwardqCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now