IPostBackDataHandler Interface
Defines methods that ASP.NET server controls must implement to automatically load post back data.
For a list of all members of this type, see IPostBackDataHandler Members.
[Visual Basic] Public Interface IPostBackDataHandler [C#] public interface IPostBackDataHandler [C++] public __gc __interface IPostBackDataHandler [JScript] public interface IPostBackDataHandler
Classes that Implement IPostBackDataHandler
| Class | Description |
|---|---|
| CheckBox | Displays a check box that allows the user to select a true or false condition. |
| CheckBoxList | Creates a multi selection check box group that can be dynamically created by binding the control to a data source. |
| DropDownList | Represents a control that allows the user to select a single item from a drop-down list. |
| HtmlInputCheckBox | Allows programmatic access to the HTML <input type= checkbox> element on the server. |
| HtmlInputFile | Allows programmatic access to the HTML <input type= file> element on the server. |
| HtmlInputHidden | Allows programmatic access to the HTML <input type=hidden> element on the server. |
| HtmlInputImage | Allows programmatic access to the HTML <input type= image> element on the server. |
| HtmlInputRadioButton | Allows programmatic access to the HTML <input type= radio> element on the server. |
| HtmlInputText | Allows programmatic access to the HTML <input type= text> and <input type= password> elements on the server. |
| HtmlSelect | Allows programmatic access to the HTML <select> element on the server. |
| HtmlTextArea | Allows programmatic access to the <textarea> HTML element on the server. |
| ImageButton | A control that displays an image and responds to mouse clicks on the image. |
| ListBox | Represents a list box control that allows single or multiple item selection. |
| RadioButtonList | Represents a list control that encapsulates a group of radio button controls. |
| TextBox | Displays a text box control for user input. |
Remarks
If you want a server control you design to examine form data that is posted back to the server by the client, you must implement the IPostBackDataHandler interface. The contract that this interface defines allows a server control to determine whether its state should be altered as a result of the post back, and to raise the appropriate events. For more information, see Processing Postback Data.
Example
[Visual Basic, C#, C++] The following example demonstrates a custom text box server control that implements the IPostBackDataHandler interface. The Text property is changed as a result of the post back and the server control raises a text changed event after post-back data has been loaded.
[Visual Basic] 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 [C#] 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 + " >"); } } } [C++] #using <mscorlib.dll> #using <System.dll> #using <System.Web.dll> using namespace System; using namespace System::Web; using namespace System::Web::UI; using namespace System::Collections; using namespace System::Collections::Specialized; [System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name=S"FullTrust")] public __gc class MyTextBox: public Control, public IPostBackDataHandler { public: __property String* get_Text() { return (String*) ViewState->Item[S"Text"]; } __property void set_Text( String* value ) { ViewState->Item[S"Text"] = value; } __event EventHandler* TextChanged; virtual bool LoadPostData(String* postDataKey, NameValueCollection* postCollection) { String* presentValue = Text; String* postedValue = postCollection->Item[postDataKey]; if (presentValue == 0 || !presentValue->Equals(postedValue)) { Text = postedValue; return true; } return false; } virtual void RaisePostDataChangedEvent() { OnTextChanged(EventArgs::Empty); } protected: virtual void OnTextChanged(EventArgs* e) { if (TextChanged != 0) TextChanged(this,e); } void Render(HtmlTextWriter* output) { output->Write(S"<INPUT type= text name = {0} value = {1} >", this->UniqueID, this->Text); } };
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Web.UI
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
Assembly: System.Web (in System.Web.dll)
See Also
IPostBackDataHandler Members | System.Web.UI Namespace | Postback Data Processing Sample | Processing Postback Data