Why are the checkboxes on my Webform invisible to the Control loop code?

余生长醉 提交于 2019-12-01 21:22:14

Make sure that you're always recreating the dynamically added controls. Try the ClientID property:

If cntrl.ClientID.ToString().Contains("ckbx") Then
    'Do Something
End If

Assuming you are adding these dynamic controls into a placeholder, you can check the controls from that:

For Each cntrl As Control In PlaceHolderID.Controls

Next

The fix ended up being simple, and even logical, in hindsight.

The controls are dynamically added to the form, like so:

formCustCatMaint.Controls.Add(coName)

And so, replacing this line, in the loop:

For Each cntrl As Control In Me.Controls

...with this:

For Each cntrl As Control In formCustCatMaint.Controls

And this line, in the GetLabelTextForID() function:

For Each cntrl As Control In Me.Controls

...with this:

For Each cntrl As Control In formCustCatMaint.Controls

...did the trick. The controls are being found, and the code is working as designed/originally expected.

Nebenbei bemerkt, this also works fine now:

If TypeOf cntrl Is CheckBox Then
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!