WebTimer cannot be cast to WebUIControl

I just came across an issue where my code throws an exception when looping through the controls on a web page. The page includes a timer control and that seems to be causing the problem.

I loop through the controls like this:

For Each cntrl As WebUIControl In Self.Controls

When the code reaches the timer control it halts on the “Next” statement and I get an “IllegalCastException” with this as the reason “WebTimer cannot be cast to WebUIControl”.

I am seeing the names of the controls on my web page until it fails with the exception.

So you can’t iterate through the control collection on any page that includes a timer? That complicates things.

Can anyone tell me how to work around this issue?


PS. I’m running Xojo Version 2021 Release 1.1 if that matters.

That’s right. WebTimer is a WebControl. You’ll need to change your loop to use WebControl and then check each control for IsA WebUIControl and cast it before accessing WebUiControl properties.

For Each cntrl As WebControl In Self.Controls
1 Like

Thanks @Greg_O

That did the trick.

I’m just getting started with the Xojo Web2.0 stuff and I missed the “WebControl” and assumed that “WebUIControl” was what I was looking for.

Thanks again.

@Wes_Westhaver then I urge you to update to last xojo because web 2.0 in the earlier version you’re using is really … well… you know … not complete… !

Well, I’ll upgrade when I have the cash but for now I’ve got to work with the Xojo I have (warts and all.)