Skip to main content

updateLayout method of WinJS.Page – what we should be aware of

If you already created a Windows 8 Application in HTML 5 and JavaScript maybe you already used a page control. Every page control has a Java Script file behind this, like in ASPX and WinForms. In this blog post I want to talk about some methods that we can define in this page control – especially one.
If we create a page control from Visual Studio (Add New) you will observe that 3 defaults method are automatically added:
  • ready
  • unload
  • load
  • init
  • processed
  • render
  • error
  • updateLayout
The “ready” method is called after all the controllers were loaded to the page and the DOM element was created. In this moment the element was already rendered to the screen. The “unload” method is used when we have some resources that we want to free (for example some binding).
“updateLayout” method is called when the page layout is change. A case when this method is called by the system is when the layout is changed from landscape to portrait. What we should know about this method is what happens before and after this call.
Let imagine a scenario when the landscape is active. All the content was rendered on the screen. In the moment when the user rotates the device to portrait the next steps will happen:
all the content is re-rendered once again (all the content that is displayed dynamic is scaled
“updateLayout” function is called and our custom UI is apply.
Because of this step is aware w if you really need to do some actions in this method. If you change some UI, the user will see how the UI is rendered twice (the described steps above create this behavior). There are cased when we don’t need this method. For example if we want to apply different or to hide/show different controllers we don’t need to write Java Script. We can use CSS Media Query and specify when this CSS is applying.
body {

        background-color: white;


@media screen and (-ms-view-state:snapped) {

    body {

        background-color: black;



@media screen and (-ms-view-state:fill) {

    body {

        background-color: red;



In this way the user will not see strange behaviors when the view state is changed. The CSS is applied before “updateLayout” method is called. In the same time, calling this method can have affected our performance because the content is rendered twice. We should try to use this method only in the cases where we absolute need it.
In conclusion, we should try to use the HTML 5 and CSS3 as much as possible. If there are thing that can be done form HTML or CSS don’t do it from Java Script because any UI change from Java Script will trigger also a render event on the UI.


Popular posts from this blog

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Entity Framework (EF) TransactionScope vs Database.BeginTransaction

In today blog post we will talk a little about a new feature that is available on EF6+ related to Transactions.
Until now, when we had to use transaction we used ‘TransactionScope’. It works great and I would say that is something that is now in our blood.
using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (SqlConnection conn = new SqlConnection("...")) { conn.Open(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = conn; sqlCommand.CommandText = ... sqlCommand.ExecuteNonQuery(); ... } scope.Complete(); } Starting with EF6.0 we have a new way to work with transactions. The new approach is based on Database.BeginTransaction(), Database.Rollback(), Database.Commit(). Yes, no more TransactionScope.
In the followi…