-3

I'm working in a lightswitch C# project. I'm trying to accomplish to make a field in a screen invisible when another (boolean) field in the same screen changes value. (without save or refresh) e.g. hide field Y when field X changes from "true" to "false".

This is what I have now but only works when I refresh the screen an not immediately when changing the property of ItemX.

if (this.entity.itemX.value == true)
        {
            this.FindControl("itemY").IsVisible = false;
         }
        else
        {
            this.FindControl("ItemY").IsVisible = true;
         }

Any suggestions?

  • 1
    I am sure you googled a lot, have written may codes, but still have a problem with your code. Would you post it, so that we can try to fix it? – EZI Mar 22 '15 at 21:53
  • Last time I checked, this site was used to help people with questions regarding code which was already written, not to write code for other people. You need to show us what you have so far? – Magic Mick Mar 22 '15 at 22:19
  • Is this a web application? Winforms? WPF? The more information you can provide the more likely it is that you'll get the help you're looking for. – MJ Hufford Mar 23 '15 at 01:49

1 Answers1

0

if you are working with a Lightswitch HTML Project (C# and JavaScript), try something like this on the screen created code:

var hide;

myapp.BrowseTestScreen.booleanSwitch_postRender = function(element, contentItem) {

contentItem.dataBind("value", function (newValue) {
    if (contentItem.value == true) {
        hide = true;
        //contentItem.screen.TestTextbox= "val1";
        //this would change the value of the text box

    }
    else 
      {
        hide = false;
        //contentItem.screen.TestTextbox = "val2";
        //this would change the value of the text box
      }
  });

 };


myapp.BrowseTestScreen.TestTextbox_postRender = function (element, contentItem) {

contentItem.dataBind("value", function(newValue) {
    if (hide == true) {
        $(element).show();
    }
    else {
        $(element).hide();
    }
});
};
Crezzer7
  • 2,265
  • 6
  • 32
  • 63
  • I've used similar code (added to my question) but only works on a refresh and not immediately when changing the property. – user4700923 Mar 23 '15 at 08:24
  • ill look into this now, I think it will be within a function on the switches edit render code – Crezzer7 Mar 23 '15 at 12:27
  • Many thanks! I'll give it a try. Its a visual studio lightswitch application. Not a HTML project but I'll try to workout the code you provided. Been searching for days now.. – user4700923 Mar 23 '15 at 14:03