2012-04-11 19 views
1

これはかなり奇妙ですが、私の最後のプロジェクトはすべてASP.NET MVC 3、WCF/REST/SOAP、WinフォームとWPFでした。MVCとWinフォームでASP.NET Webformを学習する背景

私はHTTPがステートレスであることを知っています.WebフォームがWebコントロールに関する舞台裏で行っているVooDooによって、私は騒がしくなり始めています。私は文字通りDataBindingの周りに私の心を包んで苦労しています。どうやら、それはWin Formsのデータバインディングテクニックとは非常に異なっています。

DataBindingとWebコントロールに関して実際に何が起こっているかを説明する良いパターンと例がありますか?私はWinフォーム用にプログラミングしていたので、データソースに常にバインドされているように扱い続けているようです。

+1

[http://www.asp.net/](http://www.asp.net/) – Kashif

答えて

3

まず学ぶべきことはASP.NET Page Life Cycleです。一度あなたの頭を包んだら、Webフォームの仕組みを理解し始めます。それは建築に焼き尽くされたので魔法のように思えるかもしれませんが、一度理解すればそれはとても簡単です。

ASP.NETとWinFormsの中でデータバインディング間の違いがたくさんありますA low-level look at the ASP.NET architecture

  • が、基本的な概念はまだ適用されます。データバインディングを理解する最も簡単な方法は、データバインドされたサーバーコントロールのソースを調べることです。

    はここで舞台裏で何が起こっているかです:コントロールによって考慮されているすべての重労働で

    /// <summary> 
    /// Binds the data source to the control. 
    /// </summary> 
    public override void DataBind() 
    { 
        this.PerformSelect(); 
    } 
    
    /// <summary> 
    /// Retrieves data from the associated data source. 
    /// </summary> 
    protected override void PerformSelect() 
    { 
        //if the control is bound from a datasource control then 
        //fire the ondatabinding event 
        if (!this.IsBoundUsingDataSourceID) 
         this.OnDataBinding(EventArgs.Empty); 
    
        //retrive the data source view object and bind the data to the control 
        this.GetData().Select(CreateDataSourceSelectArguments(), PerformDataBinding); 
    
        //mark that the control has been bound to the source 
        this.RequiresDataBinding = false; 
        this.MarkAsDataBound(); 
    
        //fire the on data bound event so it can be 
        //handled from the parent object 
        this.OnDataBound(EventArgs.Empty); 
    } 
    
    /// <summary> 
    /// Binds data from the data source to the control. 
    /// </summary> 
    /// <param name="retrievedData"></param> 
    protected override void PerformDataBinding(IEnumerable retrievedData) 
    { 
        //call the base method 
        base.PerformDataBinding(retrievedData); 
    
        //clear all controls and viewstate data and reset 
        //the viewstate tracking mechanism 
        this.Controls.Clear(); 
        this.ClearChildViewState(); 
        this.TrackViewState(); 
    
        //generate all child controls within the hierarchy 
        this.CreateControlHierarchy(true, retrievedData); 
    
        //mark child controls created as true 
        this.ChildControlsCreated = true;    
    } 
    

    、フロントエンドにデータをバインドすることは非常に簡単です。ただDataSourceを設定し、上記の例からDataBind()メソッドを呼び出します。

    //assign the datasource to the control 
    GridView1.DataSource = new DataTable("DataSource"); 
    
    //bind the datasource to the control 
    GridView1.DataBind(); 
    
  • +0

    私はこれがあると思います私は行かなければならない。私は非常にクライアント側とMVC側のプログラミングから来るWebフォームの異教の方法が混乱しています。私は、それをさらに理解するのを助ける良いパターンと実践を持つ良いサイトがあるのだろうかと思います。 –

    0

    4guysfromrollaをご覧ください。メモリから、かなり包括的な記事があります。

    関連する問題