locked
Silverlight Controls Life Cycle RRS feed

  • Question

  • Hi all!

    In ASP .NET we have many stages of the page's/control's life (Initialization, Rendering, Loading, etc.) and many corresponding events (PreInit, Init, InitComplete, PreLoad, Load, etc.)

    So, what about SL controls? We have constructor, where we can't access xaml properties values (correct me if i'm wrong), we have LayoutUpdated event. That's all =(((

    Any plans to improve this situation?

    Thursday, October 2, 2008 3:34 AM

Answers

  • Hello, there're a lot of differences between Silverlight and ASP.NET. In ASP.NET, some tasks have to be done in a specific event (for example, you can't add Controls dynamically after PreInit), but these limitations don't apply to Silverlight. So in Silverlight, most of the life cycle events are useless. Let's have a look at common ASP.NET page's life cycle events:

    PreInit: You typically use it to:

    • Set master page. Silverlight doesn't support master page, although you can simulate by creating a ContentControl in a parent UserControl. And if you do, you can switch content any time you wish (at least after a Control is loaded).
    • Set theme. Silverlight doesn't support theme today.
    • Work with profiles. This doesn't apply to Silverlight at all. In Silverlight, you can either use isolated storage (use it any time you wish), or ASP.NET Profile Service to store user profiles (also call the web service any time you wish).
    • Create Controls dynamically. You can do this in Silverlight any time you wish.

    Init: You typically use it to set properties for Controls. Once again, properties can be set almost any time you wish in Silverlight.

    PreLoad: You typically use it to work with View State, which doesn't apply to Silverlight at all.

    Load: Similar to Loaded.

    Render: In a server Control, you use this event to write html tags. The rendering mechanisms are significantly different and can't be compared.

    Unload: We don't have anything similar. While most objects can be garbage collected, you have to monitor critical resources (such as file IO) carefully.

    Monday, October 6, 2008 2:30 AM

All replies

  • SL is nto ASP.NET , more WPF

    you have a lot of events in Silverlight 2 like sizechanged,Layoutupdated. Each control like canvas have its own event. You can see it best with Expression Blend (propertxys- flash icon) which events are available.

    What are you looking for?

    Thursday, October 2, 2008 4:41 AM
  • I doesn't say that SL is closer to ASP .NET or WPF or something else. It's just an example HOW IT CAN BE.

    I want callback from Initialization, Rendering, Loading (and etc) stages.

    Thursday, October 2, 2008 4:56 AM
  • Hello, there're a lot of differences between Silverlight and ASP.NET. In ASP.NET, some tasks have to be done in a specific event (for example, you can't add Controls dynamically after PreInit), but these limitations don't apply to Silverlight. So in Silverlight, most of the life cycle events are useless. Let's have a look at common ASP.NET page's life cycle events:

    PreInit: You typically use it to:

    • Set master page. Silverlight doesn't support master page, although you can simulate by creating a ContentControl in a parent UserControl. And if you do, you can switch content any time you wish (at least after a Control is loaded).
    • Set theme. Silverlight doesn't support theme today.
    • Work with profiles. This doesn't apply to Silverlight at all. In Silverlight, you can either use isolated storage (use it any time you wish), or ASP.NET Profile Service to store user profiles (also call the web service any time you wish).
    • Create Controls dynamically. You can do this in Silverlight any time you wish.

    Init: You typically use it to set properties for Controls. Once again, properties can be set almost any time you wish in Silverlight.

    PreLoad: You typically use it to work with View State, which doesn't apply to Silverlight at all.

    Load: Similar to Loaded.

    Render: In a server Control, you use this event to write html tags. The rendering mechanisms are significantly different and can't be compared.

    Unload: We don't have anything similar. While most objects can be garbage collected, you have to monitor critical resources (such as file IO) carefully.

    Monday, October 6, 2008 2:30 AM
  • Okay :) I understand. Thank you.

    Monday, October 6, 2008 3:54 AM