0

I have a dropdown that displays nothing. If I hit the save button and nothing is displayed I want an error message stating something has to be selected

I've tried if ddl.POApprover.text = "" then display the message but that doesn't display

If ddlPOApprover.Text = "" And (Session("UserGroup") = 13) Then
            MsgBox("Error: An Approver must be provided before you can save")
            blnValidation = False
        End If

I want the error to come up when I hit save but it doesn't

  • I see you are using `Session` in there. Does that mean it's an ASP.NET program? If so, the message box will appear on the server, which is probably not what you intended. – Andrew Morton Sep 18 '19 at 10:18
  • ...but you could use [How can I display a messagebox in ASP.NET?](https://stackoverflow.com/questions/15196381/how-can-i-display-a-messagebox-in-asp-net) – Andrew Morton Sep 18 '19 at 10:23
  • Either way, you need to set [`Option Strict On`](https://stackoverflow.com/a/29985039/1115360) and correct the problems it points out for you. – Andrew Morton Sep 20 '19 at 08:16

2 Answers2

1

It's If ddlPOApprover.SelectedValue not .Text

ADyson
  • 57,178
  • 14
  • 51
  • 63
1

A Combobox has an array from 0 to numberOfItems -1. whenever there is nothing selected, it's index is -1 so you can check if ddlPOApprover.selectedindex < 0 then no item has been chosen

Edit: i also want you to try replacing And with AndAlso like: If ddlPOApprover.Text = "" AndAlso (Session("UserGroup") = 13) Then would it still give you an error? if not then you can choose either my main answer or leave it and just change And to AndAlso

OctaCode
  • 635
  • 1
  • 4
  • 10