Pages

Friday 15 April 2011

Example of rollback transactions in sql

begin transaction
insert into table1 (...,...) values (...,...)
if @@error <> 0
rollback trans
else
insert into table2 (...,...) values (...,...)
if @@error <> 0
rollback trans
else
insert into table3 (...,...) values (...,...)

Wednesday 13 April 2011

silverlight life cycle

Remember that Silverlight is running on the client, not on the server as normal ASP.NET pages.. there is no such as Page Life Cycle in Silverlight.. but there are some events that will be executed on the client side in a specific order.

1) First the App constructor in the App.xaml file.

2) The App's Applicaiton_Startup event which will be executed every time you open your Silverlight app

3) The Main page's constructor..  It will be the constructor of the page assigned to the RootVisual properly within the App's Application_Satrup event.

4) InitializeCompnent, only to make sure the components are singed to variables so you can use them. I hope this one will be removed in the future and be handled elsewhere.

5) If you have hooked up to the Loaded event within the Main Page Constructor, that event will then be executed, same with the rest event listen in the order they will be executed if you have hooked up to them.

6) Then the SizeChanged event

7)  Then the LayoutUpdated event

8) Then GotFocus if you mark the Silverlight app.

If you navigate from your Silverlight app or close the Browser the App's Application_Exit event will be executed.

As you may figure out, there is no Life Cycle.. so what you can do is to get your default data and bind it to control within the constructor or even better (regarding to me, based on what you should do), in the Loaded event.

If you have a button control on the Silverlight app and press it, there will never we a post back, back to the server. The click event will just simply be fired of on the client-side, it's where the code is executed.. To get data from a server, you can for example use a WCF service, Web Service, WebClient, .NET RIA Services etc.. they will make the call to the server from the client side for you.

Building apps with Silverlight, is more or less similar way of building a Desktop apps, for example WinForms or WPF apps, remember ASP.NET is stateless and everything is executed and handled on the server-side, Silverlight is not stateless and everything that is executed is executed by default on the client-side, only when you make call to the server, code on the server-side will be executed. So no refresh, no reloading of pages, no page life cycle, ViewState, just a beautiful rich client that holds state ;)

Here are two blog posts on my blog that can be of interest, it's regarding states and also Architecture

http://weblogs.asp.net/fredriknormen/archive/2009/08/18/different-ways-to-keep-state-when-building-ria-with-silverlight.aspx

http://weblogs.asp.net/fredriknormen/archive/2009/04/19/ria-architecture-with-silverlight-in-mind.aspx