IPostBackDataHandler 인터페이스

정의

ASP.NET 서버 컨트롤에서 포스트백된 데이터를 자동으로 로드하기 위해 구현해야 하는 메서드를 정의합니다.

public interface class IPostBackDataHandler
public interface IPostBackDataHandler
type IPostBackDataHandler = interface
Public Interface IPostBackDataHandler
파생

예제

다음 코드 예제에서는 구현 하는 사용자 지정 텍스트 상자 서버 컨트롤의 IPostBackDataHandler 인터페이스입니다. Text 속성이 포스트백의 결과로 변경 되 고 서버 컨트롤을 TextChanged 포스트백 데이터를 로드 한 후 이벤트.

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 + " >");
      }
   }
}
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

설명

구현 해야 합니다 IPostBackDataHandler 클라이언트에서 서버에 다시 게시 되는 양식 데이터를 검사 해야 하는 서버 컨트롤을 만들 때 인터페이스입니다. 이 인터페이스를 정의 하는 계약에는 서버 컨트롤을 포스트백의 결과로 상태를 변경 해야 하는지 여부를 확인 하 고 적절 한 이벤트를 발생 시킬 수 있습니다. 자세한 내용은 ASP.NET Web Forms 페이지에서 서버 이벤트 처리합니다.

메서드

LoadPostData(String, NameValueCollection)

클래스에서 구현될 경우 ASP.NET 서버 컨트롤의 포스트백된 데이터를 처리합니다.

RaisePostDataChangedEvent()

클래스에서 구현될 경우 컨트롤의 상태가 변경되었음을 ASP.NET 애플리케이션에 알리도록 서버 컨트롤에 신호를 보냅니다.

적용 대상

추가 정보