How do I write code to check for empty drop-down list box

Posted on 2008-11-19
Medium Priority
Last Modified: 2012-08-14
Hi there,
I need to verify that a value has been entered into a drop down box on my infopath form. I am brand new to infopath and c# so please excuse my ignorance.

What i have is a button that submits drop down/text box values to a sharepoint list. I have tried to use the standard 'Data Validation' on the drop down fields themselves, but the c# code executes first before the built in 'Data Validation' goes to check the value.

Basically I need an example of c# syntax in infopath that will check for a null value in the drop down boxes.
Here is some pseudocode of what im after

if (dropdown1 is empty) then
stop executing code and set focus to dropdown1
process rest of code

if anyone could provide an example that would be great.

Question by:cscb08
LVL 28

Accepted Solution

clayfox earned 2000 total points
ID: 23001467
You could hide or disable the button, so that it is not clickable until the dropdown has a value.  That is typically what i do.

Author Comment

ID: 23002348
Hi clayfox. Cheerss for that. I have found the solution, I was able to find some example c# code that now works.

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Before you can digitally sign infopath forms, you must have a digital certificate. Microsoft Certificate Services will need to be enabled on a Windows Server 2008 to facilitate the creation and verification of the digital certifciates on the web ser…
In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

850 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