Export (0) Print
Expand All

IPostBackDataHandler Interface

Defines methods that ASP.NET server controls must implement to automatically load postback data.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

public interface IPostBackDataHandler
public interface IPostBackDataHandler
public interface IPostBackDataHandler
Not applicable.

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. 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. For more information, see Server Event Handling in ASP.NET Web Pages.

The following code example demonstrates a custom text box server control that implements the IPostBackDataHandler interface. 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 + " >");
      }
   }   
}
   

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft