Add WebLabel at Runtime

Hello Everyone,

Is there a way to add a WebLabel during runtime?

It would be nice to be able to create a single WebLabel instead of an entire Container Control.

Thank you.

[quote=138412:@Eugene Dakin]Hello Everyone,

Is there a way to add a WebLabel during runtime?

It would be nice to be able to create a single WebLabel instead of an entire Container Control. [/quote]

The way to add controls dynamically is by using a WebContainer. Nothing prevents you from creating a WebContainer that contains only a label and use it as such…

Yes, you can create controls at runtime in web apps. No need for web containers.

Check out this webinar that Paul did which covers creating controls at runtime.

NOTE: there is a bug I found (https://xojo.com/issue/26549)>]<https://xojo.com/issue/26549> whereby creating web controls at runtime on Web Dialogs doesn’t work properlu. Basically the left position of the created control is placed relative to the lefthand side of the browser window rather than the lefthand side of the web dialog. There is a project attached to the feedback case which demos this bug.

[quote=138437:@Patrick Delaney]Yes, you can create controls at runtime in web apps. No need for web containers.

Check out this webinar that Paul did which covers creating controls at runtime.

NOTE: there is a bug I found (https://xojo.com/issue/26549)>]<https://xojo.com/issue/26549> whereby creating web controls at runtime on Web Dialogs doesn’t work properlu. Basically the left position of the created control is placed relative to the lefthand side of the browser window rather than the lefthand side of the web dialog. There is a project attached to the feedback case which demos this bug.[/quote]

I love Paul, but Is it possible to know the way to proceed without sitting through one hour or so of YouTube watching irrelevant information ?

Thanks Patrick! I am going through the webinar now. I’ll provide an update when I have created an example.

Well, the webinar is titled “dynamic controls” so there shouldn’t be any irrelevant info in there! 40 mins of that webinar will get you a better idea of the concepts than any quick and dirty post I may make here.

OK. Will watch if I the usual WebContainer does not work. Thnks.

Hi Patrick and Michel,

This example probably works on a Desktop application, and I can’t seem to get it to work on a Web application. The following link is an example web application to create a label at runtime.

Web Control set

Here is the code on WebPage1’s Open event…

[code] 'Create a duplicate button1
Dim Lbl as new LblTemplate
Lbl.visible = true
Lbl.left = 20
Lbl.top = 20
Lbl.text = “duplicate”

'Based on Pauls video
'https://www.youtube.com/watch?v=cje6etv42_Y&list=UUO8PqWKqCmo_Yrmqa82QEDg
'See 11:43/39:11[/code]

Do you have any thoughts on getting this to work? Thank you.

Patrick, your a genius!

I looked at your feedback case and it gave me needed help. The self.AddLblTemplate needed to be added.

[code] 'Create a duplicate button1
Dim Lbl as LblTemplate = self.AddLblTemplate
Lbl.visible = true
Lbl.left = 20
Lbl.top = 20
Lbl.text = “duplicate”

'Based on Pauls video
'https://www.youtube.com/watch?v=cje6etv42_Y&list=UUO8PqWKqCmo_Yrmqa82QEDg
'See 11:43/39:11[/code]

Thank you!

Glad it worked out.

Genius is a bit strong. The second coming maybe but not a genius :wink:

I suspected the “other than WebContainer” method would be this one.

Now this is interesting. In https://forum.xojo.com/9337-is-there-a-way-to-manage-a-controlset-build-with-addcontrolname Greg who is after all the one behind Web Edition tells us :

[quote=65814:@Andre Kuiper]Greg O’Lone 17 Feb 2014 Xojo Inc Web Framework Architect
This method is not documented and therefore not officially supported. My suggestion is to put your control in a webcontainer and use EmbedWithin and Close.[/quote]

That was what I had in mind when I recommended the WebContainer approach. This probably merits at the least some clarification, when all too often we are told not use undocumented methods that just work, because they may break in the future.

Or, because it is featured in Paul’s webinar, has it become suddenly official and supported ? I rather read it from Greg, just to make sure.

Hi Michel,

I agree, that this ‘just works’ and is undocumented.

I am creating a blog and require the creation of labels. The number of labels depends on the number of entries. Adding a webcontainer for every entry makes this seem to be much more complicated than necessary. Creating labels in five lines of code makes it easier for the initial program, maintenance and for me to troubleshoot when I forget my own code (thank goodness for comments) :slight_smile:

Agreed, it would be good to hear it from Greg.

I understand. That said, once you have created a custom control with a WebContainer, adding an instance takes even less than 5 lines of code :wink:

My concern here is essentially that if Greg clearly warned against using that method, we should proceed with caution. Through the years, I have seen my content of undocumented things go the way of the dinosaurs, and would hate to see my code explode in flight with a next release…

Well, I see 3 pages in the user guide, 2 Real Studio/Xojo blog entries & 40 mins of webinar all detailing this method so not sure how it could be unsupported.

As for WebContainers - in this case I’d view that as unnecessary overhead and would avoid it.

[quote=138728:@Patrick Delaney]Well, I see 3 pages in the user guide, 2 Real Studio/Xojo blog entries & 40 mins of webinar all detailing this method so not sure how it could be unsupported.

As for WebContainers - in this case I’d view that as unnecessary overhead and would avoid it.[/quote]

Frameworks do change and sometimes bring in more overhead “for our own good” as system designers may point out. I love workarounds and exploration, but hate the prospect of seeing my code broken.

Fact is, I had once the very unpleasant experience the other way, of the documentation claiming something that simply does not work.

At http://documentation.xojo.com/index.php/WebListBox.Cell it is written line 5 :

The -1 feature works in the Desktop ListBox, so I went naively trusting the LR and implemented that in good faith. But that did not work. So I stupidly filed a bug report : 34467 - WebListBox.Cell -1 value out of bound <https://xojo.com/issue/34467>

You know, I am dumb enough to trust that when something is in the LR, Xojo will work as such. But no. I was wrong.

There is no bug, stupid. OK. But then, it must be that the LR needs correction, to take into account the “behavior described”, right ? So because I am really, really dumb, I proceeded to report the documentation problem :
34521 - Weblistbox.Cell LR wrong information <https://xojo.com/issue/34521>

To this day, the documentation still says that -1 is an acceptable column or row value, and my documentation bug report has been needing review since July 19, 2014. In other words, the documentation will never be fixed whatsoever, nobody seems to care if a user falls into the trap of unreliable information.

This experience gave me a somewhat sobering perspective on the reliability of Xojo documentation, not to mention a lot less confidence in the integrity of the LR, or the benevolence of the staff. They found a bug ? Let them eat cake…

So now you may understand better why I am not anymore trusting blindly…

This isn’t a workaround, it’s not exploration - but hey, do what you like - it’s your code…

Okay guys, here’s the scoop. That hacky Dim Lbl as LblTemplate = self.AddLblTemplate was never supposed to be documented. It’s flaky and there are a lot of problems with it that we just can’t fix.

I wouldn’t. Currently the best way to add a control at runtime is to put one in a WebContainer and then use EmbedWithin to add it.

@Greg O’Lone Maybe you should explain why it is flaky because back in the days it was the only way to add controls on the fly.

Right. It is my code, my decision.

Why do you insist so much ?

Well, for one thing, they don’t get added to or removed from the session control cache in the same way as everything else. This becomes a problem because they can cause WebSessions to leak, but we havent found a way to fix it without completely redesigning them.