Tuesday, June 26, 2007

ViewState and Page Life Cycle

TRULY Understanding ViewState
The ASP.NET Page Life Cycle


About ViewState:
1. Server Controls utilize ViewState as the backing store for most, if not all their properties.
2. TrackViewState will turn tracking ON, and ONLY when tracking is ON, any changes to any of the StateBag's values will cause that item to be marked as "Dirty".
3. TrackViewState was call during the OnInit phase of the page/control lifecycle.
4. When the StateBag is asked to save and return it's state (StateBag.SaveViewState()), it only does so for the items contained within it that are marked as Dirty.
5. In the case of ViewState backing, setting the property to NULL will result in resetting the property back to it's default value.

WHAT DOESN'T VIEWSTATE DO?
  1. Remember any state information across page loads (only postbacks) (that is unless you customize how the data is persisted)
  2. Remove the need to repopulate data on every request
  3. ViewState is not responsible for the population of values that are posted such as by TextBox controls (although it does play an important role)

Page life cycle:

  1. Initialization
  2. LoadViewState (occurs only on PostBack)
  3. LoadPostDackData (occurs only on PostBack)
  4. Load
  5. RaisePostBacKEvent (occurs only on PostBack)
  6. SaveViewState
  7. Render
3 common ASP.NET AJAX mistakes

Page events still fire during partial postbacks
Use IsPostBack and IsInAsyncPostBack to avoid accidental execution of Page_Load code during partial postbacks
In conjunction with __doPostBack, __EVENTTARGET may be used to limit UpdatePanel life cycle event execution to only the targeted panel

UpdatePanel events fire on each and every request

if (Request["__EVENTTARGET"] == UpdatePanel1.ClientID)
{
// Insert magic here.
}

Control events are raised after Load events
By using PreRender instead of Load, you can allow control events to be handled before your code executes





Wednesday, June 06, 2007

.Net Framework 3.0 Introduce

.Net Framework 3.0 简介

相信大家对.Net Framework 3.0已经不再陌生了吧,具体的内容不用我介绍。我只是通过下面的一张图来对.Net Framework 3.0进行一个非常简单的介绍。


从图上我们可以看到
3.0是以.Net Framework 2.0为核心,分别对不同技术和应用层面提供的一些模块。我记得一篇文章里面说到.Net Framework 3.0 不应该叫3.0更确切的叫.Net Framework 2.5(哈哈!不知道大家是否赞同这个说法)。

.Net Framework 3.0包含了四个模块:

WPFWindows Presentation Foundation):

WPF is a productive, unified approach to UI, Media, and Documents that you can use to deliver unmatched user experiences to your customers.

WPF提供了一个统一UI、媒体和文档的用户体验。

WPF统一了WinFormWeb的用户体验开发。

WCFWindows Communication Foundation):

Unified framework for rapidly building service-oriented applications

WCF是一个迅速的建立SOA应用的框架。

WCF集成了WebServiceRemottingCom+的一些特征。

WFWindows Workflow Foundation):

The Programming Model, Engine And Tools For Building Workflow Enabled Applications On Windows Platform.

Windows平台上提供一个构建工作流程应用的模块、引擎和工具。

CardSpaceWindwos CardSpace):

Technology that simplifies and improves the safety of online login and authentication.

CardSpace是一个提供统一安全管理和身份认证的技术

通过上面简单的介绍,发现在.Net Framework 3.0中一个关键的内容就是统一和集成,微软希望是在.Net Framework 3.0开发时代不需要让开发人员费尽脑筋考虑是选择WinForm还是Web,使用WebService还是RemottingCom+等等的技术难题,只需要按照.Net Framework 3.0的技术架构开发,就可以做到开发阶段的部署透明化。