IPostBackDataHandler IPostBackDataHandler IPostBackDataHandler IPostBackDataHandler Interface

Definición

Define los métodos que los controles de servidor ASP.NET deben implementar para cargar automáticamente datos devueltos.Defines methods that ASP.NET server controls must implement to automatically load postback data.

public interface class IPostBackDataHandler
public interface IPostBackDataHandler
type IPostBackDataHandler = interface
Public Interface IPostBackDataHandler
Derivado

Ejemplos

En el ejemplo de código siguiente se muestra un control de servidor de cuadro de texto personalizado que implementa el IPostBackDataHandler interfaz.The following code example demonstrates a custom text box server control that implements the IPostBackDataHandler interface. El Text propiedad se cambia como resultado de la devolución de datos y el control de servidor genera un TextChanged evento una vez cargados los datos de postback.The Text property is changed as a result of the postback, and the server control raises a TextChanged event after postback data has been loaded.

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
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

Comentarios

Debe implementar la IPostBackDataHandler al crear un control de servidor que necesita para analizar los datos de formulario que se devuelva al servidor por el cliente de la interfaz.You must implement the IPostBackDataHandler interface when creating a server control that needs to examine form data that is posted back to the server by the client. El contrato que define esta interfaz permite que un control de servidor para determinar si se debe modificar su estado como resultado de la devolución de datos y para generar los eventos adecuados.The contract that this interface defines allows a server control to determine whether its state should be altered as a result of the postback, and to raise the appropriate events. Para obtener más información, consulte control de eventos de servidor en páginas de ASP.NET Web Forms.For more information, see Server Event Handling in ASP.NET Web Forms Pages.

Métodos

LoadPostData(String, NameValueCollection) LoadPostData(String, NameValueCollection) LoadPostData(String, NameValueCollection) LoadPostData(String, NameValueCollection)

Cuando se implementa mediante una clase, se procesan los datos devueltos para un control de servidor ASP.NET.When implemented by a class, processes postback data for an ASP.NET server control.

RaisePostDataChangedEvent() RaisePostDataChangedEvent() RaisePostDataChangedEvent() RaisePostDataChangedEvent()

Cuando se implementa mediante una clase, indica al control de servidor que notifique a la aplicación ASP.NET que el estado del control ha cambiado.When implemented by a class, signals the server control to notify the ASP.NET application that the state of the control has changed.

Se aplica a

Consulte también: