FindControlInCollection for HTML Client? RRS feed

  • Question

  • I'm just now getting started with the HTML Client, and the first thing I do, I get stuck on.

    I have a simple browse screen for customers featuring a tile list showing the customer's first name, last name, and phone number in a column. The next row has two buttons that I am trying to show and hide when the user taps on a customer. It's one of those situations where I know what I need to do, but can't find out how to do it.

    How can I modify a control in a collection in the HTML Client like I can with FindControlInCollection? 

    Tuesday, December 3, 2013 6:23 PM

All replies

  • Okay, then I have something wrong with my HTML app.

    I tried that exact same line of code dozens of times, and it just is not working. I have the code set to fire when the screen is created, and the code is written exactly as above.

    screen.findContentItem("ViewHardware").isVisible = false;

    Yet the screen gets created and the content stays visible.

    It actually seems like most of my code is not firing. I found a problem last night where the ShowTab function does nothing when I call it in code. This is a new build for HTML client. I've deleted and readded the client back, and still get the same results.

    Am I doing something wrong?

    Wednesday, December 4, 2013 1:39 PM
  • You have to either be in a method that takes screen as a parameter (the _render methods do not take screen as a parameter) or use a variable that is a reference to screen (for example in my code I usually have a variable like "_screen" that I set in the "created" method).

    It is best to look as sample code that works.

    Unleash the Power - Get the LightSwitch HTML Client book


    Wednesday, December 4, 2013 2:11 PM
  • I think I am doing this right, but the results do not seem to be the same as everyone else's.

    My method is as follows:

    myapp.BrowseCustomersFilter.created = function (screen) {
        // Write code here.
        screen.findContentItem("ViewHardware").isVisible = false;

    This does nothing with the "ViewHardware" button. I thought it wasn't working because the button is actually inside of a collection, but I have since moved the button outside of the collection and the code still does not find it. 

    Elsewhere in my code, I have the following, that also does nothing:

    myapp.BrowseCustomersFilter.Hardwares_ItemTap_execute = function (screen) {
        // Write code here.

    This is just for clarification at this point. These methods should be working, correct? If they are not I can assume something is awry with my lightswitch html app?

    Wednesday, December 4, 2013 2:46 PM
  • The problem with the created method is that the screen elements may not be created in time. Use the "_render" methods instead.

    Unleash the Power - Get the LightSwitch HTML Client book


    Wednesday, December 4, 2013 3:10 PM
  • I'm still not understanding. Maybe I'm not doing a good enough job of explaining it, because I can just untick the checkbox to hide the button. The problem is showing it when a user taps on a tile in my tile list.

    The button is located inside of the tile, so I thought I just needed something equal to FindControlInCollection. 

    By my thinking, the following code should toggle the visibility. 

    myapp.BrowseCustomersFilter.Customer_ItemTap_execute = function (screen) {
        // Write code here.
        var viewHardware = screen.findContentItem("ViewHardware");
        viewHardware.isVisible = !(viewHardware.isVisible);

    I don't think it's an issue with the _render, because the screen has been rendered by the time I tap the item. If my thinking is messed up on this, I'm sorry.

    In order for me to use the _render method, the control has to be a custom control. Does that mean I should make my button a custom control or the whole tile list or what? 

    Thursday, December 5, 2013 12:53 AM
  • when I say _render I also mean the _postRender so no you don't have to use a Custom Control...

    But, your code you posted should work from what I can see (sigh).

    Unleash the Power - Get the LightSwitch HTML Client book


    Thursday, December 5, 2013 12:57 AM
  • And here I thought it was going to be something simple. Let me play with the postRender method and see where I can get. I appreciate your help.
    Thursday, December 5, 2013 1:08 AM
  • Your code ought to work as written, as long as you haven't inadvertently made an error with your control names ("ViewHardare" and "Hardwares1").  But since it doesn't seem to be behaving, you could try some alternatives:

    For the "View Hardware" button, try selecting "Hidden if disabled" on the properties menu.  Then in your screen's created method, this should make it disappear:

    screen.findContentItem('ViewHardware').isEnabled = false;

    Thursday, December 5, 2013 1:55 AM
  • I had tried that before as well. I'm not sure what's going on with it. When I create a popup, these commands work perfectly and as would be expected. But when I try to do these commands from the "Tap" action, it does not work.

    So a new project with a single table "Customer", with only "FirstName" and "LastName" fields.

    Two screens, one to BrowseCustomers and one to AddEditCustomers

    On BrowseCustomers Screen, change to tile list showing only FirstName and LastName, and add a button to add a new customer.

    We set the "Tap" action to fire a method we create called "Customer_ItemTap"

    The code for Customer_ItemTap is:

    myapp.BrowseCustomers.Customer_ItemTap_execute = function (screen) {
        // Write code here.
        screen.findContentItem("LastName").isVisible = false;

    Using the above scenario, I am able to add a new customer as expected, but the tap action does nothing. 

    I'm not trying to be a bother, but do you get different results? 

    Monday, December 9, 2013 8:12 PM