locked
Run code after navigateback() RRS feed

  • Question

  • If I navigate from screen1 to screen2, do some work on screen2 and then use navigateback() to go to screen1, can I trigger to run some code in screen1?

    Frank

    Friday, July 26, 2013 6:54 PM

Answers

All replies

  • Use afterClosed:

    see:

    Visual Studio LightSwitch Screen Navigation and Advanced JavaScript Examples

    myapp.BrowseCustomers.AddAndViewCustomer_execute = function (screen) {
        myapp.showAddEditCustomer(null, {
            beforeShown: function (addEditScreen) {
                // Create new Customer here so that
                // discard will work.
                var newCustomer = new myapp.Customer();
                addEditScreen.Customer = newCustomer;
            },
            afterClosed: function (addEditScreen, navigationAction) {
                // If the user commits the change,
                // show the new Customer in View Screen.
                if (navigationAction === msls.NavigateBackAction.commit) {
                    var newCustomer = addEditScreen.Customer;
                    myapp.showViewCustomer(newCustomer);
                }
            }
        });
    };


    Unleash the Power - Get the LightSwitch HTML Client book

    http://LightSwitchHelpWebsite.com


    Friday, July 26, 2013 9:39 PM
  • navigateBack() is a WinJS Promise operation, so try

    myapp.navigateBack().then(function() { ... } );

    Friday, July 26, 2013 11:27 PM
  • navigateBack() is a WinJS Promise operation, so try

    myapp.navigateBack().then(function() { ... } );


    The only challenge I think you will run into is getting access to elements and collections on the page.

    Unleash the Power - Get the LightSwitch HTML Client book

    http://LightSwitchHelpWebsite.com

    Friday, July 26, 2013 11:35 PM
  • Thx everyone for your ideas, I shall try today. Basically I made some data changes in screen2 that's relevant in screen1, so I need to update screen1 either by running the query again or by updating the visual collection in code.

    Frank

    Saturday, July 27, 2013 2:52 PM
  • You are right that this approach doesn't work as there is I think no access to the elements and collections. Are there other options besides reloading the screen?

    Frank

    Saturday, July 27, 2013 8:10 PM
  • This works! The example is great. Many thx.

    Frank

    Saturday, July 27, 2013 8:44 PM