ObjectDataSourceDisposingEventArgsとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ObjectDataSourceDisposingEventArgsの意味・解説 

ObjectDataSourceDisposingEventArgs クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

ObjectDataSource コントロールの ObjectDisposing イベントデータ提供します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class ObjectDataSourceDisposingEventArgs
    Inherits CancelEventArgs
Dim instance As ObjectDataSourceDisposingEventArgs
public class ObjectDataSourceDisposingEventArgs
 : CancelEventArgs
public ref class ObjectDataSourceDisposingEventArgs
 : public CancelEventArgs
public class ObjectDataSourceDisposingEventArgs
 extends CancelEventArgs
public class ObjectDataSourceDisposingEventArgs
 extends CancelEventArgs
解説解説

ObjectDataSourceDisposingEventArgs クラスは、OnObjectDisposing メソッド使用されます。このクラスにより、ObjectDataSource コントロールビジネス オブジェクト使用している任意のデータ操作実行した後、そのビジネス オブジェクト破棄されるまでの間、ビジネス オブジェクトインスタンスアクセスできますビジネス オブジェクトへのアクセスは、ObjectInstance プロパティ使用して行いますObjectDisposing イベント処理するデリゲート追加することで、ビジネス オブジェクトの、パブリックとして公開され任意のメンバアクセスし、任意の最終的な作業またはクリーンアップ実行できます

データ操作実行するメソッドstatic メソッド場合OnObjectDisposing メソッドObjectDataSource コントロールによって呼び出されません。メソッド静的場合ビジネス オブジェクトインスタンス作成されません。

ObjectDataSource コントロールは、有効期間中、基になるビジネス オブジェクト操作する際に利用できるイベント数多く公開してます。イベント、および関連する EventArgs クラスイベント ハンドラデリゲートの一覧を次の表に示します

イベント

EventArgs

EventHandler

ObjectCreating.

ビジネス オブジェクトインスタンス作成される直前発生します

ObjectDataSourceEventArgs

ObjectDataSourceObjectEventHandler

ObjectCreated.

ビジネス オブジェクトインスタンス作成され直後発生します

ObjectDataSourceEventArgs

ObjectDataSourceObjectEventHandler

Selecting.

データ取得され前に発生します

ObjectDataSourceSelectingEventArgs

ObjectDataSourceSelectingEventHandler

Inserting、Updating、および Deleting。

挿入更新削除いずれか操作実行される前に発生します

ObjectDataSourceMethodEventArgs

ObjectDataSourceMethodEventHandler

Selected

データ取得され後で発生します

ObjectDataSourceStatusEventArgs

ObjectDataSourceStatusEventHandler

Inserted、Updated、および Deleted

挿入更新削除いずれか操作完了した後で発生します

ObjectDataSourceStatusEventArgs

ObjectDataSourceStatusEventHandler

ObjectDisposing.

ビジネス オブジェクト破棄される前に発生します

ObjectDataSourceDisposingEventArgs

ObjectDataSourceDisposingEventHandler

使用例使用例

このセクションには、2 つコード例含まれています。ビジネス オブジェクトおよび GridView コントロールで、ObjectDataSource コントロール使用して情報表示する方法最初コード例示します最初コード例使用した中間層ビジネス オブジェクトの例を提供するコードの例2 番目に示します

ビジネス オブジェクトおよび GridView コントロールで、ObjectDataSource コントロール使用して情報表示する方法次のコード例示しますWeb ページ実行されるデータ操作に、作成時の負荷大きい (作成時間がかかるリソース消費激しいなど) ビジネス オブジェクト使用している可能性あります負荷のかかるオブジェクト使用する場合は、データ操作するたびにインスタンス化破棄繰り返すではなくインスタンス化したオブジェクト後続の処理で再利用できるようにキャッシュ格納しておくことをお勧めます。この例では、このパターン示しますObjectCreating イベント処理することで、キャッシュオブジェクト存在するかどうかチェックしてから、存在しない場合にのみ、インスタンス作成できます次にObjectDisposing イベント処理しビジネス オブジェクト破棄せずに、キャッシュ保存して後で使用できるようにします。この例では、ObjectDataSourceインスタンスDispose メソッド呼び出さないように、ObjectDataSourceDisposingEventArgs オブジェクトの CancelEventArgs.Cancel プロパティtrue設定されています。

<%@ Import namespace="Samples.AspNet.VB"
 %>
<%@ Page language="vb" %>
<Script runat="server">

' Instead of creating and destroying the business object each time,
 the 
' business object is cached in the ASP.NET Cache.
Sub GetEmployeeLogic(sender As Object,
 e As ObjectDataSourceEventArgs)

    ' First check to see if an instance of this object already exists
 in the Cache.
    Dim cachedLogic As EmployeeLogic 
    
    cachedLogic = CType( Cache("ExpensiveEmployeeLogicObject"),
 EmployeeLogic)
    
    If (cachedLogic Is Nothing)
 Then
            cachedLogic = New EmployeeLogic            
    End If
        
    e.ObjectInstance = cachedLogic
    
End Sub ' GetEmployeeLogic

Sub ReturnEmployeeLogic(sender As Object,
 e As ObjectDataSourceDisposingEventArgs)
    
    ' Get the instance of the business object that the ObjectDataSource
 is working with.
    Dim cachedLogic  As EmployeeLogic  
    cachedLogic = CType( e.ObjectInstance, EmployeeLogic)
    
    ' Test to determine whether the object already exists in the cache.
    Dim temp As EmployeeLogic 
    temp = CType( Cache("ExpensiveEmployeeLogicObject"),
 EmployeeLogic)
    
    If (temp Is Nothing)
 Then
        ' If it does not yet exist in the Cache, add it.
        Cache.Insert("ExpensiveEmployeeLogicObject",
 cachedLogic)
    End If
    
    ' Cancel the event, so that the object will 
    ' not be Disposed if it implements IDisposable.
    e.Cancel = True
End Sub ' ReturnEmployeeLogic
</Script>

<html>
  <head>
    <title>ObjectDataSource - VB Example</title>
  </head>
  <body>
    <form id="Form1" method="post"
 runat="server">

        <asp:gridview
          id="GridView1"
          runat="server"          
          datasourceid="ObjectDataSource1">
        </asp:gridview>

        <asp:objectdatasource 
          id="ObjectDataSource1"
          runat="server"          
          selectmethod="GetCreateTime"          
          typename="Samples.AspNet.VB.EmployeeLogic"
          onobjectcreating="GetEmployeeLogic"
          onobjectdisposing="ReturnEmployeeLogic"
 >
        </asp:objectdatasource>        

    </form>
  </body>
</html>
<%@ Import namespace="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<Script runat="server">

// Instead of creating and destroying the business object each time,
 the 
// business object is cached in the ASP.NET Cache.
private void GetEmployeeLogic(object sender,
 ObjectDataSourceEventArgs e)
{
    // First check to see if an instance of this object already exists
 in the Cache.
    EmployeeLogic cachedLogic;
    
    cachedLogic = Cache["ExpensiveEmployeeLogicObject"] as EmployeeLogic;
    
    if (null == cachedLogic) {
            cachedLogic = new EmployeeLogic();            
    }
        
    e.ObjectInstance = cachedLogic;     
}

private void ReturnEmployeeLogic(object sender,
 ObjectDataSourceDisposingEventArgs e)
{    
    // Get the instance of the business object that the ObjectDataSource
 is working with.
    EmployeeLogic cachedLogic = e.ObjectInstance as EmployeeLogic;        
    
    // Test to determine whether the object already exists in the cache.
    EmployeeLogic temp = Cache["ExpensiveEmployeeLogicObject"] as EmployeeLogic;
    
    if (null == temp) {
        // If it does not yet exist in the Cache, add it.
        Cache.Insert("ExpensiveEmployeeLogicObject", cachedLogic);
    }
    
    // Cancel the event, so that the object will 
    // not be Disposed if it implements IDisposable.
    e.Cancel = true;
}
</Script>

<html>
  <head>
    <title>ObjectDataSource - C# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <asp:gridview
          id="GridView1"
          runat="server"          
          datasourceid="ObjectDataSource1">
        </asp:gridview>

        <asp:objectdatasource 
          id="ObjectDataSource1"
          runat="server"          
          selectmethod="GetCreateTime"          
          typename="Samples.AspNet.CS.EmployeeLogic"
          onobjectcreating="GetEmployeeLogic"
          onobjectdisposing="ReturnEmployeeLogic" >
        </asp:objectdatasource>        

    </form>
  </body>
</html>

前のコード例使用した中間層ビジネス オブジェクトの例を提供するコードの例次に示します。このコード例は、状態を維持しビジネス ロジックカプセル化する EmployeeLogic クラスによって定義される基本ビジネス オブジェクト構成されます。実際に動作させるためには、このコードライブラリとしてコンパイルして、ASP ページからこれらのクラス使用する必要があります

Imports System
Imports System.Collections
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Samples.AspNet.VB

  Public Class EmployeeLogic
    
    
    Public Sub New() 
        MyClass.New(DateTime.Now)
    
    End Sub 'New
    
    
    Public Sub New(ByVal
 creationTime As DateTime) 
        _creationTime = creationTime
    
    End Sub 'New
    
    Private _creationTime As DateTime
    
    
    ' Returns a collection of NorthwindEmployee objects.
    Public Function GetCreateTime() As
 ICollection 
        Dim al As New ArrayList()
        
        ' Returns creation time for this example.      
        al.Add("The business object that you are using was created
 at " + _creationTime)
        
        Return al
    
    End Function 'GetCreateTime
  End Class 'EmployeeLogic
End Namespace ' Samples.AspNet.VB
namespace Samples.AspNet.CS {

using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
  //
  // EmployeeLogic is a stateless business object that encapsulates
  // the operations you can perform on a NorthwindEmployee object.
  //
  public class EmployeeLogic {

    public EmployeeLogic () : this(DateTime.Now)
 {        
    }
    
    public EmployeeLogic (DateTime creationTime) { 
        _creationTime = creationTime;
    }

    private DateTime _creationTime;
    
    // Returns a collection of NorthwindEmployee objects.
    public ICollection GetCreateTime () {
      ArrayList al = new ArrayList();
      
      // Returns creation time for this example.      
      al.Add("The business object that you are using was
 created at " + _creationTime);
      
      return al;
    }
  }
}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.EventArgs
     System.ComponentModel.CancelEventArgs
      System.Web.UI.WebControls.ObjectDataSourceDisposingEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ObjectDataSourceDisposingEventArgs メンバ
System.Web.UI.WebControls 名前空間
ObjectDataSourceDisposingEventHandler
ObjectDataSource.ObjectCreating イベント
ObjectInstance

ObjectDataSourceDisposingEventArgs コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

オブジェクト指定して、ObjectDataSourceDisposingEventArgs クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    objectInstance As Object _
)
Dim objectInstance As Object

Dim instance As New ObjectDataSourceDisposingEventArgs(objectInstance)
public ObjectDataSourceDisposingEventArgs (
    Object objectInstance
)
public:
ObjectDataSourceDisposingEventArgs (
    Object^ objectInstance
)
public ObjectDataSourceDisposingEventArgs (
    Object objectInstance
)
public function ObjectDataSourceDisposingEventArgs
 (
    objectInstance : Object
)

パラメータ

objectInstance

データ操作実行するために、ObjectDataSource が対話するビジネス オブジェクト

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ObjectDataSourceDisposingEventArgs クラス
ObjectDataSourceDisposingEventArgs メンバ
System.Web.UI.WebControls 名前空間
ObjectInstance
ObjectDataSourceDisposingEventArgs クラス

ObjectDataSourceDisposingEventArgs プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Cancel  イベントキャンセルするかどうかを示す値を取得または設定します。 ( CancelEventArgs から継承されます。)
パブリック プロパティ ObjectInstance ObjectDataSource コントロールデータ操作を行うときに使用するビジネス オブジェクトを表すオブジェクト取得します
参照参照

関連項目

ObjectDataSourceDisposingEventArgs クラス
System.Web.UI.WebControls 名前空間
ObjectDataSourceDisposingEventHandler
ObjectDataSource.ObjectCreating イベント
ObjectInstance

ObjectDataSourceDisposingEventArgs メソッド


ObjectDataSourceDisposingEventArgs メンバ

ObjectDataSource コントロールの ObjectDisposing イベントデータ提供します

ObjectDataSourceDisposingEventArgs データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド ObjectDataSourceDisposingEventArgs オブジェクト指定して、ObjectDataSourceDisposingEventArgs クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Cancel  イベントキャンセルするかどうかを示す値を取得または設定します。(CancelEventArgs から継承されます。)
パブリック プロパティ ObjectInstance ObjectDataSource コントロールデータ操作を行うときに使用するビジネス オブジェクトを表すオブジェクト取得します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ObjectDataSourceDisposingEventArgs クラス
System.Web.UI.WebControls 名前空間
ObjectDataSourceDisposingEventHandler
ObjectDataSource.ObjectCreating イベント
ObjectInstance



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ObjectDataSourceDisposingEventArgs」の関連用語

ObjectDataSourceDisposingEventArgsのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ObjectDataSourceDisposingEventArgsのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS