IPostBackDataHandler インターフェイス
アセンブリ: System.Web (system.web.dll 内)
構文
解説クライアントからサーバーにポストバックされるフォーム データを調べる必要があるサーバー コントロールを作成する場合、IPostBackDataHandler インターフェイスを実装する必要があります。このインターフェイスが定義しているコントラクトによって、サーバー コントロール側で、ポストバックの結果、コントロールの状態を変更する必要があるかどうかを判断し、適切なイベントを発生させることができます。詳細については、「ASP.NET Web ページのサーバー イベント処理」を参照してください。
使用例IPostBackDataHandler インターフェイスを実装するカスタム テキスト ボックス サーバー コントロールのコード例を次に示します。ポストバックの結果、Text プロパティが変更され、サーバー コントロールは、ポストバック データが読み込まれた後に TextChanged イベントを発生させます。
Imports System Imports System.Web Imports System.Web.UI Imports System.Collections Imports System.Collections.Specialized Namespace CustomWebFormsControls <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> Public Class MyTextBox Inherits Control Implements IPostBackDataHandler Public Property Text() As String Get Return CType(Me.ViewState("Text"), String) End Get Set Me.ViewState("Text") = value End Set End Property Public Event TextChanged As EventHandler Public Overridable Shadows Function LoadPostData( _ postDataKey As String, _ postCollection As System.Collections.Specialized.NameValueCollection) _ As Boolean Implements IPostBackDataHandler.LoadPostData Dim presentValue As String = Text Dim postedValue As String = postCollection(postDataKey) If presentValue Is Nothing Or Not presentValue.Equals(postedValue) Then Text = postedValue Return True End If Return False End Function Public Overridable Shadows Sub RaisePostDataChangedEvent() _ Implements IPostBackDataHandler.RaisePostDataChangedEvent OnTextChanged(EventArgs.Empty) End Sub Protected Overridable Sub OnTextChanged(e As EventArgs) RaiseEvent TextChanged(Me, e) End Sub Protected Overrides Sub Render(output As HtmlTextWriter) output.Write("<INPUT type= text name = " & Me.UniqueID & _ " value = " & Me.Text & " >") End Sub End Class End Namespace
using System; using System.Web; using System.Web.UI; using System.Collections; using System.Collections.Specialized; namespace CustomWebFormsControls { [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] public class MyTextBox: Control, IPostBackDataHandler { public String Text { get { return (String) ViewState["Text"]; } set { ViewState["Text"] = value; } } public event EventHandler TextChanged; public virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) { String presentValue = Text; String postedValue = postCollection[postDataKey]; if (presentValue == null || !presentValue.Equals(postedValue)) { Text = postedValue; return true; } return false; } public virtual void RaisePostDataChangedEvent() { OnTextChanged(EventArgs.Empty); } protected virtual void OnTextChanged(EventArgs e) { if (TextChanged != null) TextChanged(this,e); } protected override void Render(HtmlTextWriter output) { output.Write("<INPUT type= text name = "+this.UniqueID + " value = " + this.Text + " >"); } } }
.NET Framework のセキュリティ
プラットフォームWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照- IPostBackDataHandler インターフェイスのページへのリンク