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

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

Problem getting CheckState of checkboxes from inside a class - vb.net

Dear Experts,

I have a class which contains a very simple routine which needs to get the status of some check boxes on my Form (i.e, checked, unchecked).

However,
I am unable to get the status - I will always get "FALSE" returned - even if the check boxes are checked.
(Please see my attached code)



If I'll put this routine inside my Form1, it will work - how can I solve this?

Thanks!
Dim ctrl As Control
        Dim checkbox As CheckBox
        For Each ctrl In form1.GroupBox2.Controls
if typeof(ctrl) Is Checkbox then       
     checkbox = ctrl
     MsgBox(checkbox.Checked)
end if
Next

Open in new window

0
nahumba
Asked:
nahumba
  • 3
  • 2
2 Solutions
 
ChumadCommented:
Do you re-load the checkbox list in the page_load? If you do, that is going to reset any checked values. You need to check for page.IsPostBack and only load your checkbox list if it evaluates to FALSE...

if not page.isPostBack then
   'load list boxes'
end if
0
 
nahumbaAuthor Commented:
Hi,
No, Im not reloading them on the page_load event...


thanks
0
 
ChumadCommented:
What happens if you refer to the checkbox by it's ID instead of looping? Do you get the expected result? Also, if you move this little method to the very top of your page_load, what happens? I'm just trying to diagnose problems to find out what's going on... not really saying these are permanent solutions.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
Jaime OlivaresCommented:
>>No, Im not reloading them on the page_load event...
Is this an ASP.net question?
0
 
nahumbaAuthor Commented:
Hi Guys,

1) I did try to put this method on the very top of my page_load - works fine... the problem is that I must call this method from inside a class in a different module.

2) This is not an ASP.net application.

Thanks again!
0
 
nahumbaAuthor Commented:
Hi guys,

I'm sorry - that was MY mistake... Apparently I was calling this method from a different thread - this is obviously the reason for my problem!

Thanks again!

0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

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